我有一个对象,我想生成一个JSON对象。 目前我有一个被另一个对象(ResourceObject)包装的对象。 此资源对象仅在顶级对象上具有公开变量的子集。
我使用此资源对象通过注释来生成json。这是为了保持原始对象更清洁,因为它在代码中的其他位置使用。但是,维护此过滤代码会增加复杂性,并且主要是样板代码。
理想情况下,我想传递对象和预期的架构来为我做过滤,但我没有看到类似的东西。我希望我的搜索条件不正确。
示例Class1
SELECT a.id
, c.name_first
, c.name_last
, a.created AS app_created
, a.edited
, a.comments AS custcomment
, c.name_company
, a.loan_amount
, a.product_type
, ap.packager AS placed_with
, a.introducer_id
, a.status
, c.contact_number
, c.email
, a.database
, bd.legal_structure
, ca.id AS address_id
, ca.address_postcode
, ca.resident_status
FROM cl_application a
LEFT
JOIN cl_application_business_details bd
ON bd.id = a.id
LEFT
JOIN cl_customer c
ON c.id = a.customer_id
AND c.deleted IS NOT NULL
LEFT
JOIN cl_application_packager ap
ON ap.application_id = a.id
AND ap.status != 'Declined'
AND ap.deleted = '0000-00-00 00:00:00'
LEFT
JOIN ( SELECT ca1.customer_id
, MAX(ca1.created) AS latest_created
FROM cl_customer_address ca1
WHERE ca1.deleted = '0000-00-00 00:00:00'
GROUP BY ca1.customer_id
) lc
ON lc.customer_id = a.customer_id
LEFT
JOIN cl_customer_address ca
ON ca.customer_id = lc.customer_id
AND ca.created = lc.latest_created
AND ca.deleted = '0000-00-00 00:00:00'
WHERE a.deleted = '0000-00-00 00:00:00'
GROUP BY a.created, a.id
ORDER BY a.created, a.id
示例资源类
Class1 {
private String name = "C1";
private String version = "1.0";
public String getName() {
return name;
}
public String getVersion() {
return version;
}
}
示例架构
ResourceClass1 {
private Class1 class1;
ResourceClass1 (Class1 c1) {
class1 = c1;
}
public String getName() {
return class1.getName();
}
}
现在,从Resource类中获取JSON会给我一些影响:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Class1",
"type" : "object",
"properties" : {
"name" : {
"type" : "string"
},
}
}
是否有一个包只通过传入schema和java对象来获得相同的json?