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.

what do you want the delimiters to be? how do you want to parse it? these are important factors when u decide to parse something, and im unable to get much information regarding these from your code.
personally, iv always used bufferedReader and string split methods for parsing with good results in good timing too , and the file you provided , shouldnt be too hard to parse either. but , need to know about the above two factors.

StoreReporter.class.getResourceAsStream doesn't do what you expect it to do. It tries to load a resource and return the corresponding stream relative to the class. Replace it with a new File(yourpath) and let us know how it goes.

@spowel4 : i apologise for my 1st post, as i google , i see that i didnt comprehend a lot of stuff , and made the post with simple file parsing ideas running in my mind. this is a problem more advanced members.. sorry.

somjit{} - No problem, thanks for trying to help me.
~s.o.s~ - I changed from the .getResourceAsStream to this: Stores myStores = mapper.readValue(new File("s:\\sw7\\stores\\storeEmails.json"), Stores.class); and it appears to be parsing correctly now, thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.