0

I have a JSON layout where the outer structure field is an array which everything else is par of it.

 {
   "attribute1":[
     {
       "@attribute2":"something",
       "attribute3":"something too",
       "attribute4":["something else"],
       "attribute5":{
           "what":"dont know",
           "carrier":"mailto:something@gmail.com"
        }
     }
   ] 

}

I have the following POJO class:

public class Dataset {

     private List<object> attribute1;
     private String attribute2;
     private String[] attribute3;
     private Map<String, String> attribute4;
}

I have the accessors and getters methods defined too.

I instantiate the class ObjectMapper to use the readValue method to serialize the above file using the POJO class.

I have two issues: 1. How I define attribute1 so it contains everything that is embedded as array list? 2. When I try to parse the @attribute2 it errors out. I have to remove the @ in order to pass this error. The file contains lot of attributes with @ sign.

How do I handle that from the source file without modifying it?

mjocasio
  • 1
  • 1
  • Besides solving the error it is not recommended to use such signs for attributes [see here](https://stackoverflow.com/a/25368854/4998135) What you could do would be a custom serializer which does the same as the generic one jackson constructs but with removing all `@` and such things. So that it is a parsable JSON file. – Nico Jun 06 '17 at 13:09
  • I believe I will need to create Custom Type reference for List TypeReference> mapType = new TypeReference>() {}; List jsonToPersonList = objectMapper.readValue("location\data.json", mapType); Is this a start.... I did modified but I getting an error cannot deserialize instance of ArrayList out of start_object token – mjocasio Jun 06 '17 at 13:33
  • So how in the first place the @ got define part of the json formatting. I have been told this is a json file. Im assuming should be able to read it... you are requesting to remove all the @ present in every field before commencing the parse. Is this correct? – mjocasio Jun 06 '17 at 13:38

0 Answers0