2017-12-18 2 views
0

json에없는이 생성자에이 새 파일을 추가 할 수 없어서 오류 아래 누군가가 나를 도와주세요. 나는 두 개의 주석 @JsonIgnoreProperties을 시도하고 @JsonIgnore 및 @JsonIgnoreProperties (ignoreUnknown = TRUE) 및 클래스 수준 및 생성자 수준은@JsonProperty @JsonIgnoreProperties

다음은 내 코드 및 오류 세부 사항은

을 만들 // 같은

public static class Location { 
     private String a; 
     @Wither private int b; 
     @Wither private int c; 
     @Wither private int d; 
     @Wither private int newFiled; //which not there in json 

를 따릅니다 한

@JsonCreator 
    public Location(@JsonProperty("A") String a, 
          @JsonProperty("B") int b, 
          @JsonProperty("C") int b, 
          @JsonProperty("D") int d, 
          int newFiled) { 
      this.a = a; 
      this.b = b; 
      this.c = c; 
      this.d = d; 
      this.newFiled = newFiled; 
     } 

     public int newFiled() { 
      return a+b+c; 
        } 


Error: 

} 2017-12-18 12:53:24,194 WARN o.s.h.c.j.MappingJackson2HttpMessageConverter [I/O dispatcher 3] Failed to evaluate deserialization for type [simple type, class com.gap.plan.allocati 
fasterxml.jackson.databind.JsonMappingException: Argument #4 of constructor [constructor for com.gap.plan.allocation.model.SkuInventory$DCLocation, annota 
tions: {interface [email protected]rxml.jackson.annotation.JsonIgnoreProperties(ignoreUnknown=true, allowGetters=false, value=[], allow 
Setters=false), interface [email protected]son.annotation.JsonCreator(mode=DEFAULT)}] has no property name annotation; must have name w 
hen multiple-parameter constructor annotated as Creator 
{} 2017-12-18 12:53:24,196 ERROR c.g.p.a.s.ProductAllocationService [ForkJoinPool-2-worker-36] Unknown processing error 
org.springframework.web.client.RestClientException: Could not extract response: no suitable HttpMessageConverter found for response type [class com.gap.plan.allocation.model.SkuInven 
tory] and content type [application/json;charset=UTF-8] 
     at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:109) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE] 
     at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:835) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE] 
     at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:819) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE] 
     at org.springframework.web.client.AsyncRestTemplate$ResponseExtractorFuture.convertResponse(AsyncRestTemplate.java:680) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE] 
     at org.springframework.web.client.AsyncRestTemplate$ResponseExtractorFuture.adapt(AsyncRestTemplate.java:667) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE] 
     at org.springframework.web.client.AsyncRestTemplate$ResponseExtractorFuture.adapt(AsyncRestTemplate.java:642) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE] 
     at org.springframework.util.concurrent.FutureAdapter.adaptInternal(FutureAdapter.java:100) ~[spring-core-4.2.4.RELEASE.jar:4.2.4.RELEASE] 
     at org.springframework.util.concurrent.ListenableFutureAdapter$1.onSuccess(ListenableFutureAdapter.java:56) ~[spring-core-4.2.4.RELEASE.jar:4.2.4.RELEASE] 
     at org.springframework.util.concurrent.ListenableFutureCallbackRegistry.success(ListenableFutureCallbackRegistry.java:118) ~[spring-core-4.2.4.RELEASE.jar:4.2.4.RELEASE] 
     at org.springframework.http.client.HttpComponentsAsyncClientHttpRequest$HttpResponseFutureCallback.completed(HttpComponentsAsyncClientHttpRequest.java:121) ~[spring-web-4.2.4 
.RELEASE.jar:4.2.4.RELEASE] 
     at org.springframework.http.client.HttpComponentsAsyn                              c 
ClientHttpRequest$HttpResponseFutureCallback.completed(HttpComponentsAsyncClientHttpRequest.java:102) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE] 
     at org.apache.http.concurrent.BasicFuture.completed(BasicFuture.java:119) ~[httpcore-4.4.4.jar:4.4.4] 
     at org.apache.http.impl.nio.client.DefaultClientExchangeHandlerImpl.responseCompleted(DefaultClientExchangeHandlerImpl.java:177) ~[httpasyncclient-4.1.1.jar:4.1.1] 
     at org.apache.http.nio.protocol.HttpAsyncRequestExecutor.processResponse(HttpAsyncRequestExecutor.java:432) ~[httpcore-nio-4.4.4.jar:4.4.4] 
     at org.apache.http.nio.protocol.HttpAsyncRequestExecutor.inputReady(HttpAsyncRequestExecutor.java:325) ~[httpcore-nio-4.4.4.jar:4.4.4] 
     at org.apache.http.impl.nio.DefaultNHttpClientConnection.consumeInput(DefaultNHttpClientConnection.java:267) ~[httpcore-nio-4.4.4.jar:4.4.4] 
     at org.apache.http.impl.nio.client.InternalIODispatch.onInputReady(InternalIODispatch.java:81) ~[httpasyncclient-4.1.1.jar:4.1.1] 
     at org.apache.http.impl.nio.client.InternalIODispatch.onInputReady(InternalIODispatch.java:39) ~[httpasyncclient-4.1.1.jar:4.1.1] 
     at org.apache.http.impl.nio.reactor.AbstractIODispatch.inputReady(AbstractIODispatch.java:123) ~[httpcore-nio-4.4.4.jar:4.4.4] 
     at org.apache.http.impl.nio.reactor.BaseIOReactor.readable(BaseIOReactor.java:164) ~[httpcore-nio-4.4.4.jar:4.4.4] 
     at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvent(AbstractIOReactor.java:339) ~[httpcore-nio-4.4.4.jar:4.4.4] 
     at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvents(AbstractIOReactor.java:317) ~[httpcore-nio-4.4.4.jar:4.4.4] 
     at org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIOReactor.java:278) ~[httpcore-nio-4.4.4.jar:4.4.4] 
     at org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor.java:106) ~[httpcore-nio-4.4.4.jar:4.4.4] 
     at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$Worker.run(AbstractMultiworkerIOReactor.java:590) ~[httpcore-nio-4.4.4.jar:4.4.4] 
     at java.lang.Thread.run(Thread.java:748) ~[?:1.8.0_131] 
+0

이 필드는 JSON 문서의 일부가 아닌 것을 알고있는 경우 JsonCreator와 anntated 생성자의 매개 변수로 newFiled를 추가하는 poijt은 무엇입니까? 그냥 생성자에 추가하지 마십시오. –

+0

@JB Nizet 생성자 필드에 해당 필드를 추가하지 않으면 던지는 오류 –

+1

그리고 오류는 무엇입니까? –

답변

0

필드 레벨에 @JsonIgnore 주석을 추가 할 수 있습니다. 또는 생성자에서 제거하고 setter 메서드를 사용하여 값을 할당 할 수 있습니다.

@JsonCreator 
    public Location(@JsonProperty("A") String a, 
          @JsonProperty("B") int b, 
          @JsonProperty("C") int b, 
          @JsonProperty("D") int d) { 
      this.a = a; 
      this.b = b; 
      this.c = c; 
      this.d = d; 
     } 

     public int setNewFiled(int newFiled) { 
        this.newFiled = newFiled; 
     } 
+0

도 작동하지 않습니다. –

관련 문제