Using this example json file:
{
"stores": [
{
"storeName":"AUGUSTA",
"company":"CC",
"emailAddresses": ["spowel4@gmail.com", "spowel4@yahoo.com", "steve@compsysplus.com"]
},
{
"storeName":"CHATTANOOGA",
"company":"CC",
"emailAddresses": ["spowel4@gmail.com"]
}
]
}
I have this code to try to parse the file:
public static void main(final String[] args) throws Exception {
// TODO code application logic here
ObjectMapper mapper = new ObjectMapper();
Stores myStores = mapper.readValue(StoreReporter.class.getResourceAsStream("s:\\sw7\\stores\\storeEmails.json"), Stores.class);
for (final Store store : myStores.getStores()) {
System.out.println(store);
}
}
public class Stores {
private List<Store> stores;
public List<Store> getStores() {
return stores;
}
public void setStores(List<Store> stores) {
this.stores = stores;
}
}
public class Store {
private String storeName;
private String[] emailAddresses;
public String getStoreName() {
return storeName;
}
public void setStoreName(String storeName) {
this.storeName = storeName;
}
public String[] getEmailAddresses() {
return emailAddresses;
}
public void setEmailAddresses(String[] emailAddresses) {
this.emailAddresses = emailAddresses;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("Store [storeName=").append(storeName).append(", emailAddresses=")
.append(Arrays.toString(emailAddresses)).append("]");
return builder.toString();
}
}
I am getting this error:
Exception in thread "main" com.fasterxml.jackson.databind.JsonMappingException: No content to map due to end-of-input
at [Source: UNKNOWN; line: 1, column: 1]
at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:164)
at com.fasterxml.jackson.databind.ObjectMapper._initForReading(ObjectMapper.java:2836)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:2778)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:1989)
at storereporter.StoreReporter.main(StoreReporter.java:28)
Java Result: 1
Can someone please help me understand what's wrong? The path to the file is correct.