java - Getting dynamic property names with jackson -


i need create json objects structured similarly, can contain different object names, i.e.:

    "obj1":{          "field1":1,          "field2":2      }     "obj2":{          "field1":4,          "field2":5      }     "obj3":{          "field1":7,          "field2":8      } 

how can use jackson create dynanic field names? done during run time depending on input taken

you possibly refer answer: jackson dynamic property names.

basically can use custom jsonserializer.

  @jsonproperty("p")   @jsonserialize(using = customserializer.class)   private object data;    // ...  public class customserializer extends jsonserializer<object> {   public void serialize(object value, jsongenerator jgen, serializerprovider provider) throws ioexception, jsonprocessingexception {     jgen.writestartobject();     jgen.writeobjectfield(value.getclass().getname(), value);     jgen.writeendobject();   } } 

Comments

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -