POSTMAN,REST,JSON
Your method is expecting only one Cities
object, but you are passing an array of it. Change@RequestBody Cities cities
to
@RequestBody List<Cities> cities
if you really want an array.
Parsing JSON into custom POJO which has Map as one it's class member
The error message points to the problem: the offers
field is declared as a map while in JSON it is an array of maps.
Try to change Map<String, OfferCookieBean> offers = new HashMap<String, OfferCookieBean>()
to List<Map<String, OfferCookieBean>> offers;
and see what happens.
JAVA Jackson Parsing JSON Response that Contains List/Array
Your JSON is malformed. As you can see from the error message:
[Source: [{"user":{"userId":"fa6491aeb", ..........];
it seems the parser has encountered an array instead of an object.
Jackson: "Unexpected token (VALUE_STRING), expected FIELD_NAME:" when deserializing empty string instead of expected object
Ok, so sometimes all it takes to get an answer is to ask yourself the right question. It turns out, I think I was looking at an older version of the javadocs, because I discovered @JsonTypeInfo#defaultImpl
and that has set me on to the right track.
Now I have something that looks like this:
@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
include = JsonTypeInfo.As.PROPERTY,
property = "type"
defaultImpl = EmptyThing.class)
@JsonSubTypes({
@JsonSubTypes.Type(value = Thing.class, name = "Thing"),
@JsonSubTypes.Type(value = FancyThing.class, name = "FancyThing")
})
public class Thing {
...
}
public class EmptyThing extends Thing {
public EmptyThing(String s) {
// Jackson wants a single-string constructor for the default impl
}
}
Related Topics
How to Set a Timeout on a Spring Boot Rest API
Resttemplate: How to Send Url and Query Parameters Together
How to Disable Log4J Logging from Java Code
Find Everything Between Two Xml Tags With Regex
Regular Expression for Excluding Special Characters
How to Post Form Data With Spring Resttemplate
Testing @Postconstruct With Mockito
How to Return a Select Query from JPA Repository With Foreign Key Type
Spring Data JPA How to Locate Attribute With the Given Name
Selenium Webdriver: Modifying Navigator.Webdriver Flag to Prevent Selenium Detection
Regular Expression (Regex). How to Ignore or Exclude Everything in Between
Cannot Construct Instance of 'Java.Time.Localdate' - Spring Boot, Elasticseach, Jackson
How to Make a Multipart/Form-Data Post Request Using Java
How to Map Json Field Names to Different Object Field Names
How to Have Each Record of Json on a Separate Line
Duplicate Entry Exception: Spring Hibernate/Jpa Cascade Save Many to One
How to Solve Liquibase Checksum Validation Fail After Liquibase Upgrade
How to Prevent Xss Attacks or Untrusted Data in Rest API Json Using Java