2017-08-09 13 views
0

エラーJSONのパースエラーが取得し、JavaオブジェクトをJSON文字列をマッピングすることができません:JSON解析エラー:クラスのインスタンスを作成することはできません

:com.test.CPInput $ EVC $ユニ

エラーのインスタンスを作成することはできません

{ 
"timestamp": 1502270576300, 
"status": 400, 
"error": "Bad Request", 
"exception": "org.springframework.http.converter.HttpMessageNotReadableException", 
"message": "**JSON parse error: Can not construct instance of com.test.CPInput$Evc$Uni: can only instantiate non-static inner class by using default, no-argument constructor; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of com.test.CPInput$Evc$Uni: can only instantiate non-static inner class by using default, no-argument constructor at [Source: [email protected]; line: 20, column: 9] (through reference chain: com.test.CPInput["evc"]->com.test.CPInput$Evc["uni"]->java.util.ArrayList[0]**)", 
"path": "/demo/addCustomer" 
} 

JSON

{ 
    "customerId": "abcdef", 
    "customerSegment": { 
    "customerType": "customer type", 
    "customerSubtype": "subtype", 
    "industry": "industry", 
    "subIndustry": "subindustry", 
    "specialPopulation": " spl population" 
    }, 
    "evc": { 
    "evcId": "evcid", 
    "action": "PR", 
    "serviceId": "assigned prod id", 
    "previousValues": { 
     "previousName":"evcId", 
     "previousValue":"EVC id - OLD" 
    }, 
    "uni": [ 
     { 
     "type": "uniA", 
     "uniId": "uni id", 
     "siteId": "sidt id", 
     "tspCode": "tsp code", 
     "elocId": "e loc id", 
     "siteClli": "site clli", 
     "uniAction": "PR", 
     "previousValues": { 
      "previousName":"evcId", 
      "previousValue":"EVC id - OLD" 
     } 
     }, 
     { 
     "type": "uniZ", 
     "siteId": "sidt id", 
     "tspCode": "tsp code", 
     "elocId": "e loc id", 
     "siteClli": "site clli", 
     "uniAction": "PR", 
     "previousValues": { 
      "previousName":"evcId", 
      "previousValue":"EVC id - OLD" 
     } 
     } 
    ] 
    }, 
    "solutionType": "EPL", 
    "source": "Orion" 
} 

CPInput.java

public class CPInput { 


    private String customerId; 
    private CustomerSegment customerSegment; 
    private Evc evc; 
    private String solutionType; 
    private String source; 

    public CPInput() { 
     super(); 
    } 

    public class CustomerSegment{ 
     private String customerType; 
     private String customerSubtype; 
     private String industry; 
     private String subIndustry; 
     private String specialPopulation; 
     //getter setter 

    } 

    public class Evc{ 
     private String evcId; 
     private String action; 
     private String serviceId; 
     private PreviousValues previousValues; 
     private List<CPInput.Evc.Uni> uni=new ArrayList<CPInput.Evc.Uni>(); 
     //getter setter 

     public class PreviousValues{ 
      private String previousName; 
      private String previousValue; 
      //getter setter 

     } 


     public class Uni{ 
      private String type; 
      private String uniId; 
      private String siteId; 
      private String tspCode; 
      private String elocId; 
      private String siteClli; 
      private String uniAction; 
      private PreviousValues previousValues; 
      //getter setter 

      public class PreviousValues{ 
       private String previousName; 
       private String previousValue; 
       //getter setter 

    } 

//getter setter 

} 
CustomerSegment、EVC、PreviousValuesとユニ:10

DemoController.java

@RestController 
@SpringBootApplication(scanBasePackages = {"com.test"}) 
@RequestMapping(value = "/demo") 
public class DemoController { 

    @RequestMapping(method = RequestMethod.POST, value = "/addCustomer") 
    public CPOutput addCustomer(@RequestBody CPInput input) { 
     System.out.println(input);  
     return null; 
    } 

} 
+0

私は静的に内部クラスを作成し、問題を解決しました。 – ravi

答えて

2

はのために静的な内部クラスを使用してみてください。

私は常に静的な内部クラスを使用していますが、私はそのような問題はありません。

+0

この問題の説明は次のとおりです。http://www.cowtowncoder.com/blog/archives/2010/08/entry_411.html – MicNeo

関連する問題