1

I want to read/load a JSON file from another module's /resources directory to the current module and map the JSON using jackson.

Current module name is "transform" and the resource file that I need is in another module named "schema". I have added "schema" as a maven dependency in the pom.xml file of the "transform" module.

I need to read/load a file named "example.json" in the "schema" module.

But I keep getting the following error:

com.fasterxml.jackson.databind.JsonMappingException: No content to map due to end-of-input.

What I have so far:

Map<String, String> map = objectMapper.readValue(
                getClass().getClassLoader().getResourceAsStream("/schema/resources/example.json"),
                                                new TypeReference<Map<String, String>>(){});

Let's just say the full path to example.json is "/schema/resources/example.json".

danksim
  • 617
  • 3
  • 9
  • 27
  • 1
    Have a try with the following maven plugin [http://stackoverflow.com/questions/5292283/use-a-dependencys-resources](http://stackoverflow.com/questions/5292283/use-a-dependencys-resources) – Satish Oct 05 '16 at 17:17

1 Answers1

2
Map<String, String> map = objectMapper.readValue(Thread.currentThread().getContextClassLoader().getResourceAsStream("/schema/resources/example.json"),
                                            new TypeReference<Map<String, String>>(){});
user1615664
  • 591
  • 2
  • 11
  • 24
  • 1
    Thanks! I tried something very similar and it worked. Here is what I did: `objectMapper.readValue(MyClassInDifferentModule.class.getResourceAsStream("/schema/resources/example.json"), new TypeReference>(){});` – danksim Oct 06 '16 at 00:57