0

i use spring boot, jquery and spring rest controller

i try to save a list of object.

i sent to the server

{"defaultConfigDto":[{"fieldName":"","defaultConfigId":"","fieldValue":"0.2"},{"defaultConfigId":"","fieldName":"","fieldValue":"0.3"}]}

In my rest controller i have

@RequestMapping(value = "/tax", method = RequestMethod.POST)
public Long saveTax(@RequestBody List<DefaultConfigDto> defaultsConfigs) {
    return defaultConfigService.saveTaxe(defaultsConfigs);
}

My DefaultConfigDto object

public class DefaultConfigDto {
    private Long defaultConfigId;
    private String fieldName;
    private String fieldValue;
}

In the server i see this error

com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token

My html

<div class="form-group">
    <input type="hidden" id="defaultConfigDto[0].fieldName" name="defaultConfigDto[0].fieldName">
    <input type="hidden" id="defaultConfigDto[0].defaultConfigId" name="defaultConfigDto[0].defaultConfigId">
    <label for="tvqRate" class="col-sm-2 control-label">Tvq</label>
    <div class="col-sm-10">
        <input type="text" class="form-control" id="tvqRate" name="defaultConfigDto[0].fieldValue" placeholder="tax 1">
    </div>
</div>
<div class="form-group">
    <input type="hidden" id="defaultConfigDto[1].defaultConfigId" name="defaultConfigDto[1].defaultConfigId">
     <input type="hidden" id="defaultConfigDto[1].fieldName" name="defaultConfigDto[1].fieldName">
     <label for="tpsRate" class="col-sm-2 control-label">Tps</label>
     <div class="col-sm-10">
         <input type="text" class="form-control" id="tpsRate" name="defaultConfigDto[1].fieldValue" placeholder="tax 2">
      </div>
</div>

what i need to modify to get only the list?

2
  • Should your json key be "defaultsConfigs"? Commented Jun 10, 2016 at 2:30
  • 1
    Your JSON looks like an object with a defaultConfigDto field, with the defaultConfigDto field being an array of DefaultConfigDto objects. You may need to create a class public class DefaultConfigs { private List<DefaultConfigDto> defaultConfigDto; }. Commented Jun 10, 2016 at 3:13

1 Answer 1

1

With your data like this:

{"defaultConfigDto":[{"fieldName":"","defaultConfigId":"","fieldValue":"0.2"},      {"defaultConfigId":"","fieldName":"","fieldValue":"0.3"}]}

Your @RequestBody type should be like this:

public Long saveTax(@RequestBody Map<String, List<DefaultConfigDto>> defaultsConfigs) 
Sign up to request clarification or add additional context in comments.

Comments

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.