#Jackson Read Operations

6 messages · Page 1 of 1 (latest)

azure anchor
#

Anyone have a good read method that uses generics for Jackson?

cold yokeBOT
#

Hey, @azure anchor!
Please remember to /close this post once your question has been answered!

azure anchor
#
    public E get(Path path, Class<E> eClass) {
        try {
            return mapper.readValue(path.toFile(), eClass);
        } catch (IOException ex) {
            return null;
        }
    }``` This feels close, but it's not doing what I want it to
#
 public E get(Path path, Class<E> eClass) {
        try {
            byte[] bytes = Files.readAllBytes(path);
            System.out.println(new String(bytes));
            return mapper.readValue(bytes, eClass);
        } catch (IOException ex) {
            return null;
        }
    }``` with this implementation,  it shows that it is reading from the path correctly, its just not assigning the bytes to the generic class properly
#

I think its an issue with object mapper