JsonException No _valueDeserializer assigned

前端 未结 2 1227
Happy的楠姐
Happy的楠姐 2021-01-06 05:00

I\'ve a classic spring web app with some spring crud repository.

I\'m trying to save my entities within a classic angular form and i\'m getting randomly this error :

相关标签:
2条回答
  • 2021-01-06 05:50

    I think this issue occurs only when you serialize for the first time an Exchange entity. Maybe Jackson save a "copy" of attributes for each Object ?

    To prevent infinite loop, you added this annotation :

    @JsonIgnoreProperties(value = {"exchange"})
    @OneToMany(mappedBy = "exchange")
    private List<HalfFlow> halfFlows;
    

    So, my guess is Jackson "blacklist" property exchange of Halfflow bean.

    Workaround : Use an ObjectMapper for each entity on your controller :

    ObjectMapper mapper = new ObjectMapper();
    
    @RequestMapping(method = RequestMethod.POST)
    public ResponseEntity<HalfFlow> save(@RequestBody String json) throws JsonParseException, JsonMappingException, IOException {
        HalfFlow node = mapper.readValue(json, HalfFlow.class);
        HalfFlow halfflow = mapper.convertValue(node, HalfFlow.class);
    
    0 讨论(0)
  • 2021-01-06 05:57

    As Alex said, to prevent the infinite recursion, you added this annotation

    @JsonIgnoreProperties(value = {"exchange"})
    @OneToMany(mappedBy = "exchange")
    private List<HalfFlow> halfFlows;
    

    So I actually solved this issue by adding the following to the annotation

    @JsonIgnoreProperties(value = {"exchange"}, allowSetters = true)
    @OneToMany(mappedBy = "exchange")
    private List<HalfFlow> halfFlows;
    

    This solution is better explained here https://softwareengineering.stackexchange.com/questions/300115/best-way-to-deal-with-hibernate-1-many-relationship-over-rest-json-service

    0 讨论(0)
提交回复
热议问题