jeudi 15 février 2018

Dynamic binding of JsonProperty during deserialization

I'm wondering if there is any legit way to dynamically allocate name of JsonProperty so I would change it over time when needed ? With that being said I mean having :

@JsonIgnoreProperties(ignoreUnknown = true)
public class Record
{
    public String Name;

    @JsonIgnoreProperties(ignoreUnknown = true)
    public static class QueryResult<T>
    {
       public List<T> records;
    }

    public static class QueryResultRecord extends QueryResult<Record>
    {
    }
}

Like above, I have a property Name, which by default will be named "Name" like this:

[
  {
    Name: "Test",
  },
  {
     Name: "test",
  },
]

Even though I have flexibility to use @JsonProperty("name") that's not a solution. What I am after is changing it multiple times when needed as I have some parameterized query which relies on it. So I would like to have Name, FirstName, LastName and so on. Is refletion api the right thing to use it here ?





Aucun commentaire:

Enregistrer un commentaire