java - how to use @JsonProperty in this case - jackson API with lombok -


i know how use @jsonproperty in jackson api below case different.

i've below json snippet.

{"results":[{"uniquecount":395} 

so, parse jackson api above json, i've written below java pojo class.

package com.jl.models;  import lombok.data;  @data public class results {     private int uniquecount;  } 

later, got parse below similar json snippet.

{"results":[{"count":60} 

now, problem here i'm unable parse json results class expects string uniquecount.

i can create java pojo class having count member variable i've create parent java classes having instance of results class.

so, there way can customize results class having lombok behaviour parse both json without impacting each others?

thanks in advance.

you can use jackson's @jsonanysetter annotation direct unknown keys 1 method , there can assignment yourself:

@data public class results {     private int uniquecount;      // unknown properties go here     @jsonanysetter     public void setunknownproperty(string key, object value) {         if (key.equals("count")) {             uniquecount = (integer)value;         }     } } 

Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -