jackson and guava multimap serialization and deserialization.

2,703 views
Skip to first unread message

Pablo Conesa

unread,
Nov 17, 2014, 7:14:55 AM11/17/14
to jackso...@googlegroups.com
Hi guys! I need some help on something I believe should be easy but I'm not getting it right.

I want to serialise and deserialise this Table Class (vary simplified for clarity purposes):


import com.google.common.collect.LinkedHashMultimap;

public class Table {

 
private LinkedHashMultimap<String,Field> fields;


 
public Table(){
 
this.fields = LinkedHashMultimap.create();
 
};


 
public Table (LinkedHashMultimap<String, Field> fields){
 
this.fields= fields;
 
}


 
public LinkedHashMultimap<String, Field> getFields() {
 
return fields;
 
}


 
public void setFields(LinkedHashMultimap<String, Field> fields) {
 
this.fields = fields;
 
}


}



Before I didn't have the default constructor.


I'm aware of this, but Im not returning a multimap, the multimap sits in the middle of a complex data structure, and the jackson-datatype-guava dependency, which I believe is there to solve my "basic" problem.

I have added the guava module to the ObjectMapper as well, but calling readValue();

 // Add guava serialization for multimaps (Table.Fields is a multimap now).
 
ObjectMapper mapper = new ObjectMapper();
 mapper
.registerModule(new GuavaModule());

return mapper.readValue(response, valueType);




I've tried different approach but all of them have "polluted" my Table class with @JsonIgnore annotations, @JsonProperites with additional getters and setters to bypass multimap returning and receiving a Java Map, and then converting the map into a multimap. Since it still hasn't work and I feel I'm going in the wrong direction I'm posting my case here.

I'm sorry if this is a very naive question, It's not clear to me how should I use the jackson-datatype-guava dependency.....probably I'm just missing a good example link or a more exhaustive documentation than JacksonModuleGuava, JacksonFeatureModules, or the 404 page I get with the link at the bottom of the jackson-guava github repo.

Shall I implement a serialiser, deserialiser?

Tatu Saloranta

unread,
Nov 17, 2014, 1:10:10 PM11/17/14
to jackso...@googlegroups.com
Yes, your usage of Guava module is correct, and it should work that way, with no custom annotations.

What is the specific problem you are having? The usual way to trouble-shoot would be to start with an instance, serialize, and see how structure is serialized by Jackson (given that for some types there are multiple structural choices); this should then be structure Jackson expects for deserialization.

-+ Tatu +-

--
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 jackson-user...@googlegroups.com.
To post to this group, send email to jackso...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages