来自Field名称的JsonPath

时间:2015-07-27 14:21:31

标签: java json parsing error-handling

我正在开发一个编排服务。该服务基本上是一个调用多个下游服务并传递它们返回的错误的平台。问题是下游服务返回的错误字段是根据该服务的json模式。 例如 -

"details": [ { "field": "downstream_service.request.path.field_name" } ]

然而,我的组件需要返回类似

之类的错误

"details": [ { "field": "my_component/users/index/field_name" } ]

我有my_component的java POJO对象,我需要获取名为field_name的字段的json路径。

如何从POJO或Json对象获取字段的json路径?我正在寻找现有的库或框架。

USER POJO

public class User extends HATEOASEntity implements ResourceModel {

 /**
 * Credentials allowed by the user.
 * 
 */
@JsonProperty("credentials")
@Valid
private List<Credential> credentials = new ArrayList<Credential>();
/**
 * The business information collected from the customer to create a business
 * user.
 * 
 */
@JsonProperty("business_details")
@Valid
private BusinessDetails businessDetails; 
}

业务详情POJO

public class BusinessDetails {

/**
 * contact details entered by user.
 * 
 */
@JsonProperty("phone_contacts")
@Valid
private List<Phone> phoneContacts = new ArrayList<Phone>();
/**
 * addresses entered by user
 * 
 */
@JsonProperty("addresses")
@Valid
private List<Address> addresses = new ArrayList<Address>();
}

ADDRESS POJO

public class Address {

/**
 * Reference Identifier
 * 
 */
@JsonProperty("id")
private String id;
/**
 * type of the address
 * 
 */
@JsonProperty("type")
private Address.Type type;
/**
 * line-1 of the address
 * 
 */
@JsonProperty("line1")
private String line1;
/**
 * line-2 of the address
 * 
 */
@JsonProperty("line2")
private String line2;
}

我的下游服务会告诉我错误在Line_1。已将Line_1映射到我的架构定义的line1。我如何返回user/business_details/addresses/line1

0 个答案:

没有答案