0

私はjacksonとfasterxmlを使用しています。しかし、私は何にでも注釈を付けることができ、注釈に反応はありません。java オブジェクトを json オブジェクトに解析してから、springresttemplate を使用して投稿する必要があります。私は常に JsonMappingException を受け取ります。これは、null オブジェクト参照があることを示しています。しかし、コードはこのフィールドに @JsonIgnore で注釈されています。

JavaClass import com.fasterxml.jackson.annotation.JsonIgnore; は次のとおりです。com.fasterxml.jackson.annotation.JsonIgnoreProperties をインポートします。

@JsonIgnoreProperties(ignoreUnknown = true)
public class SkillGruppeTO extends NamedBaseObject implements Serializable {

private static final long serialVersionUID = 1L;
@JsonIgnore
private RolleTO rolleToAssign;

public SkillGruppeTO() {
    super();
}
@JsonIgnore
public SkillGruppeTO(Long id, String name) {
    this(id, name, null);
}
@JsonIgnore
public SkillGruppeTO(long id, String skillGruppeName, RolleTO rolleToAssign) {
    this.id = id;
    this.name = skillGruppeName;
    this.rolleToAssign = rolleToAssign;
}

@JsonIgnore
public RolleTO getRolleToAssign() {
    return rolleToAssign;
}
@JsonIgnore
public void setRolleToAssign(RolleTO rolle) {
    this.rolleToAssign = rolle;
}
}

呼び出し

  final String formatedUrl = BASE_URL + "auspraegungen";
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("auspraegungen", auspraegungTOs);
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    HttpEntity request = new HttpEntity(jsonObject, headers);
    RestTemplate restTemplate = new RestTemplate();

   MitarbeiterTO[] mitarbeiterArray =  restTemplate.postForObject(formatedUrl, request, MitarbeiterTO[].class, MITARBEITER_METHOD);
    return Arrays.asList(mitarbeiterArray);

そして、それがスタックトレースです

org.springframework.http.converter.HttpMessageNotWritableException: Could not write content: null object (through reference chain: net.sf.json.JSONObject["auspraegungen"]->net.sf.json.JSONArray[0]->net.sf.json.JSONObject["skill"]->net.sf.json.JSONObject["gruppe"]->net.sf.json.JSONObject["rolleToAssign"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: null object (through reference chain: net.sf.json.JSONObject["auspraegungen"]->net.sf.json.JSONArray[0]->net.sf.json.JSONObject["skill"]->net.sf.json.JSONObject["gruppe"]->net.sf.json.JSONObject["rolleToAssign"])
at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.writeInternal(AbstractJackson2HttpMessageConverter.java:238)
at org.springframework.http.converter.AbstractHttpMessageConverter.write(AbstractHttpMessageConverter.java:208)
at org.springframework.web.client.RestTemplate$HttpEntityRequestCallback.doWithRequest(RestTemplate.java:769)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:558)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:521)
at org.springframework.web.client.RestTemplate.postForObject(RestTemplate.java:321)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:94)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.rules.ExpectedException$ExpectedExceptionStatement.evaluate(ExpectedException.java:168)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:74)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:211)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:94)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Caused by: com.fasterxml.jackson.databind.JsonMappingException: null object (through reference chain: net.sf.json.JSONObject["auspraegungen"]->net.sf.json.JSONArray[0]->net.sf.json.JSONObject["skill"]->net.sf.json.JSONObject["gruppe"]->net.sf.json.JSONObject["rolleToAssign"])
at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:210)
at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:177)
at com.fasterxml.jackson.databind.ser.std.StdSerializer.wrapAndThrow(StdSerializer.java:187)
at com.fasterxml.jackson.databind.ser.std.MapSerializer.serializeFields(MapSerializer.java:495)
at com.fasterxml.jackson.databind.ser.std.MapSerializer.serialize(MapSerializer.java:412)
at com.fasterxml.jackson.databind.ser.std.MapSerializer.serialize(MapSerializer.java:27)
at com.fasterxml.jackson.databind.ser.std.MapSerializer.serializeFields(MapSerializer.java:491)
at com.fasterxml.jackson.databind.ser.std.MapSerializer.serialize(MapSerializer.java:412)
at com.fasterxml.jackson.databind.ser.std.MapSerializer.serialize(MapSerializer.java:27)
at com.fasterxml.jackson.databind.ser.std.MapSerializer.serializeFields(MapSerializer.java:491)
at com.fasterxml.jackson.databind.ser.std.MapSerializer.serialize(MapSerializer.java:412)
at com.fasterxml.jackson.databind.ser.std.MapSerializer.serialize(MapSerializer.java:27)
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serializeContents(CollectionSerializer.java:117)
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serializeContents(CollectionSerializer.java:23)
at com.fasterxml.jackson.databind.ser.std.AsArraySerializerBase.serialize(AsArraySerializerBase.java:183)
at com.fasterxml.jackson.databind.ser.std.MapSerializer.serializeFields(MapSerializer.java:491)
at com.fasterxml.jackson.databind.ser.std.MapSerializer.serialize(MapSerializer.java:412)
at com.fasterxml.jackson.databind.ser.std.MapSerializer.serialize(MapSerializer.java:27)
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:114)
at com.fasterxml.jackson.databind.ObjectMapper.writeValue(ObjectMapper.java:1887)
at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.writeInternal(AbstractJackson2HttpMessageConverter.java:231)
... 37 more
Caused by: net.sf.json.JSONException: null object
at net.sf.json.JSONObject.verifyIsNull(JSONObject.java:2875)
at net.sf.json.JSONObject.isEmpty(JSONObject.java:2232)
at com.fasterxml.jackson.databind.ser.std.MapSerializer.serialize(MapSerializer.java:399)
at com.fasterxml.jackson.databind.ser.std.MapSerializer.serialize(MapSerializer.java:27)
at com.fasterxml.jackson.databind.ser.std.MapSerializer.serializeFields(MapSerializer.java:491)
... 54 more
4

0 に答える 0