OHDSI Home | Forums | Wiki | Github

Java to JSON

@Frank @jon_duke

Hi, just wanted to follow up on one of topic points today. We use jackson for all our JSON serialization/deserialization. It has a nice annotation feature, called JsonProperty. It allows you to custom name your JSON properties, so you can follow Java conventions for your POJOs while naming your JSON properties whatever you want them to be. Here’s a sample:

  @Entity
public class City {
   @id
   Long id;
   String name;

   @JsonProperty("label")
   public String getName() { return name; }

   public void setName(String name){ this.name = name; }

   @JsonProperty("value")
   public Long getId() { return id; }

   public void setName(Long id){ this.id = id; }

I found the example here.

Ah, this looks perfect. As you say it would allow us to maintain proper java naming standards while still conforming to the way some of the R packages are exposing JSON objects. Based on some quick documentation review it appears the Jersey web service framework supports using Jackson for serialization just by registering it. Thanks!

t