Jackson and mapping fields

I was trying to use the useragentstring.com api to query and map browsers to my custom object and I did not want to name my fields with agent_type, agent_name and agent_version.

Simple solution that I found on this page was to annotate my properties in the class with:

@JsonProperty(“agent_type”)
@JsonProperty(“agent_name”)
@JsonProperty(“agent_version”)

The mapping is happening automatically.

Very simple.

Advertisements

Published by

m5c

Java developper that loves photography and good coffee

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s