I encountered a case where class level JsonSerializable annotation does not 
require registration with Simple Module  but method level does 
<https://stackoverflow.com/questions/53864236/class-level-jsonserializable-annotation-does-not-require-registration-with-modul>
. 

Here is the example I tried

@JsonSerialize(using = ItemRowSerializer.class )
        private ItemRow tes
tItem(){
            return new ItemRow("abc", Arrays.asList("item1", "item2", 
"item3"));
        }


I test it out like this


String jsonResult =  new ObjectMapper().writeValueAsString(testItem());
System.out.println(jsonResult);



I noticed that jsonString did not serialize using ItemRowSerializer.

However, when I did this, it gave the expected jsonString

 
SimpleModule module = new SimpleModule()
 module.addSerializer(ItemRowSerializer.class)
 mapper.register(module);
 String jsonResult =  new ObjectMapper().writeValueAsString(testItem());
 System.out.println(jsonResult);


On the otherhand, if I had my ItemRow class annoated with 
@JsonSerializable,  there was no need with module at all.
i.e

@JsonSerializable(using = ItemRowSerailizer
public class ItemRow<T> {...}


Since I am passing this serialized object over the wire, I do not prefer to 
write to mapper and send string representation across.

how would I go about getting method level annotation working without module 
registration?


for details on the actual serializer implementation, please refer here 
<https://stackoverflow.com/questions/53863697/jsongenerationexception-while-serializing-nested-object-using-jackson>



-- 
You received this message because you are subscribed to the Google Groups 
"jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to