Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 15th, 2012  |  syntax: None  |  size: 0.49 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. jackson serializer: get serialized object
  2. @JsonSerialize(using = MyObjectSerializer.class)
  3. public class MyObject {
  4.     public int a;
  5.     public boolean b;
  6. }
  7.        
  8. { "a": 42, "b": true}
  9.        
  10. { "a": 42, "b": true, "version": "0.1-beta" }
  11.        
  12. public static class MyObjectSerializer extends JsonSerializer<MyObject> {
  13.     @Override public void serialize(MyObject obj, JsonGenerator json, SerializerProvider provider) throws IOException, JsonProcessingException {
  14.         json.writeObject(obj);
  15.     }
  16. }