简体   繁体   中英

Serialization pojo into different json structure

I need to serialize a pojo into different json structure depending on whom I am sending request. Also I should be able to configure in some config that how field of pojo are mapped to json properties for a given request.

Can this be achived using jackson? Is there some library or api to do this?

Edit: For example:

public class Universal {
    private int id;
    private Date date;
    private String name;
    private Inner inner;
    private Map<String,Object> others;
    private List<Inner> inners;

}
public class Inner {
    private String value;
}

now above are two object i need to create dynamic json, one example for some of transformation is below

{ 
  "id":"",//value will be  id of Universal
  "detials":{
       "name":"",//value will be name of Universal
   },
   "data":[], // array of value(field of Inner) from inners 
   "ext":{
      "prop1":""// value of this field will be some (key1) value from others 
    } 
}

You can use Google Gson and rely on its type adaptors.

http://www.javacreed.com/gson-typeadapter-example/ is a good article from web

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM