0

I'm working on a project that uses Angular for the front-end and Java 1.8 for the back-end with Springboot, which is basically a simulator of builds for RPG characters (with the basic stats like health points, mana points, etc ...).

Posting a character was fine with its name, statistics.

But I'm trying to add items to the character and that's where my problem is.

Here's my POST mapping in my controller

Here's the model class for Character with its getters and setters (the get/set for the Items is also a list)

And here's how it is on my Angular project

Model , the methods in my formCharacter component.ts, my formCharacter Service and finaly the view where you chose an item.

And when I submit my form I get this error " JSON parse error: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token "

I'm sorry for the wall of text and thanks in advance if anyone has an idea on how to solve this problem.

I'm guessing it's the array of items in my Character's Object that's causing the problem of serialization?

1
  • Hello and welcome to StackOverflow. Please ask question posting code snippets not code snapshots. This makes it easier for other users to answer your question. Commented Dec 29, 2018 at 20:07

1 Answer 1

1

Here JSON is the actual problem. JSON cannot be deserialized by default into a Collection because it's not actually a JSON Array.

Be sure that the json should be like this {...} and in case of multiple elements it should be like -[{...},{...}] . for example -

{
  "characterName": "lower",
   "healthPoints":"323",
    ...
  "items": [
    ...
  ]
}
Sign up to request clarification or add additional context in comments.

1 Comment

So as you said, the json was the problem and It was simply the fact that my array wasn't initialized in my angular model.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.