Thanks a lot for your input. I tried it and it worked as expected. But I'm stuck at a situation where I want to retrieve a value from nested block, so can you help me out? For example, By calling REST API "https://xyz.com/resources/resource" gives me { "value"={"name":"abc.txt"} } and calling "https://abc.com/resources/resource" gives me {"title":"idontknow.txt"} now how can I take name out from the first json response?
Once again thanks a lot for your answer..!:) On Friday, September 8, 2017 at 9:19:49 AM UTC+5:30, Tatu Saloranta wrote: > > On Thu, Sep 7, 2017 at 5:24 AM, chetan choulwar <[email protected] > <javascript:>> wrote: > > Hi All, > > > > I'm calling different REST APIs and getting different kinda JSON > responses; > > is there any way to pick particular attribute from different JSON > responses > > and map it to a one common property of defined POJO (Resource for my > API) > > that can then be sent as a response from the REST API that I've exposed? > > > > For Example: > > By calling REST API "https://xyz.com/resources/resource" gives me > > {"name":"abc.txt"} > > and calling "https://abc.com/resources/resource" gives me > > {"title":"idontknow.txt"} > > > > And I have one resource class defined for my APIs to return i.e. > > MyResource > > { > > String fileName; > > } > > > > So is there any way that I can map "name"/"title" to fileName i.e. how > can I > > use jackson to deserialize these jsons to MyResource type? > > > > Please let me know if this is valid? and if yes, how? > > If you have many different names to use, it may be simpler to just > bind JSON to `Map` or `JsonNode`, and extract value explicitly. > > But if there are just couple of values, you can use `@JsonAlias` like: > > public class POJO { > @JsonAlias({ "name", "title" }) > public String fileName; > } > > which would then accept alternate names "name" and "title", but > serialize as "fileName" (which it also accepts). > This annotations was added in Jackson 2.9 > > -+ Tatu +- > -- You received this message because you are subscribed to the Google Groups "jackson-dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
