title: Java Properties file to JSON using Jackson
body: <p>I would like to convert a Java Properties file into JSON with nested objects. I followed an example I found <a href="https://medium.com/@cowtowncoder/reading-writing-java-properties-files-using-jackson-2-8-efd7a8da9d4c" rel="nofollow noreferrer">here</a> but I can't get it to work.</p>
  
  <p>For example, given:</p>
  
  <pre><code>objectA.version=1.0
  objectA.hostname=192.168.0.11
  objectA.port=9989
  objectB.hostname=10.0.2.15
  objectB.port=9998
  </code></pre>
  
  <p>I want:</p>
  
  <pre><code>{ 
    “objectA” : {
               "version” : "1.0"
               "host” : “192.168.0.11”,
               "port" : 9989
             },
    “objectB” : {
               "host” : “10.0.2.15”,
               "port" : 9998
             }
  }
  </code></pre>
  
  <p>This is what I have so far:</p>
  
  <pre><code>static class Endpoint
  {
      @JsonProperty("objectA")
      public ObjectA objectA;
  
      @JsonProperty("objectB")
      public ObjectB objectB;
  
  }
  static class ObjectA
  {
      public String hostname;
      public String port;
      public String version;
  }
  
  static class ObjectB
  {
      public String hostname;
      public String port;
  }
  
  try (InputStream input = getClass().getClassLoader().getResourceAsStream("file.properties"))
  {
      JavaPropsMapper mapper = new JavaPropsMapper();
      Endpoint host = mapper.readValue(input, Endpoint.class);
      String asText = mapper.writeValueAsString(host);
      System.out.println(asText);
  }
  </code></pre>
  
  <p>The output looks like this:</p>
  
  <pre><code>objectA.version=1.0
  objectA.hostname=192.168.0.11
  objectA.port=9989
  objectB.hostname=10.0.2.15
  objectB.port=9998
  </code></pre>