1

I have a pojo definition like following:

class Pojo<T>
{
    private T entity;
    //setters and getters;
}

I want to serialize this pojo into json using jackson and jaxb annotations. I want the property name in json to be the type of T not the name "entity". I tried few things with jaxb annotations but nothing worked as expected. Any help would be much appreciated.

varun
  • 684
  • 1
  • 11
  • 30
  • 1
    try writing XmlAdapter for it. Also to get the type of generic T refer to other questions http://stackoverflow.com/questions/3437897/how-to-get-a-class-instance-of-generics-type-t – sidgate Oct 30 '15 at 14:03
  • For JAXB that would be an adapter to/from a `JAXBElement`, with the runtime class of T being taken as the (local) element name. The JAXB annotation would be XmlAnyElement. - Not sure how to make j(ack)son work with this. – laune Oct 30 '15 at 15:15

0 Answers0