java - Customizing Field Name Serialization in Jackson Object Mapper -


say have bean:

public class mybean {     public string onemississipi;     public int mybestfriend;     //getters&setters&bears,oh my. } 

and using com.fasterxml.jackson databinding transform instances of pojo json output... how customize serialization of field names , can scoped global/class/field level?

e.g. wish dasherize field names:

{     "one-mississipi": "two mississippi",     "my-best-friend": 42 } 

i have spent hours in google , trawling through jackson code in order find out field serialization occurs, can't seem see anywhere may delegate custom field processing.

does have ideas functionality lies if any? appreciated

implement propertynamingstrategy , inside resolving methods use annotatedmethod, annotatedfield or annotatedparameter declaring class. can custom annotation on class , apply custom naming depending on it.

the biggest problem approach it's not possible actual concrete class being serialized or deserialized, return declaring class. won't possible override naming behavior in subtypes inherited members unless bring them subtype.

another solution using different mappers classes have different naming strategies. can make more or less transparent creating top-level "router" mapper decide mapper instance use (special care must taken configuration methods , other non ser/deser related methods). assuming have finite number of strategies solution should workable too.

the drawback of solution won't able mix different naming strategies during single serialization / deserialization run.


Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -