IdentityParser implements Parser { @Override public Map<String, Object> parse(String key, String line) { Map<String, Object> data = new HashMap<>(); String datakey = "line"; if (key != null) { datakey = key.trim(); } try { data.put(datakey, Integer.parseInt(line)); return data; } catch (Exception e) { } try { data.put(datakey, Long.parseLong(line)); return data; } catch (Exception e) { } data.put(datakey, line); return data; }  @Override Map<String, Object> parse(String key, String line);  }
@Test public void testParse() { Parser parser = new IdentityParser(); Map<String, Object> data; String lineString = "2018-09-07T08:40:41,768 | INFO | FelixStartLevel | core | 14 - " + "org.apache.aries.jmx.core - 1.1.8 | Unregistering MBean with ObjectName " + "[osgi.compendium:service=cm,version=1.3,framework=org.apache.felix.framework," + "uuid=e75146c3-f73c-46e3-878b-1b88e58d76cf] for service with service.id [16]"; System.out.println("line String :: " + lineString); data = parser.parse("line_string", lineString); Assert.assertNotNull("parser result is null", data); Assert.assertEquals("parser size result is incorrect",1, data.size()); Assert.assertTrue("parser value is not a string",data.get("line_string") instanceof String); String lineInteger = "512"; System.out.println("line Integer :: " + lineInteger); data = parser.parse("line_integer", lineInteger); Assert.assertNotNull("parser result is null", data); Assert.assertEquals("parser size result is incorrect", 1, data.size()); Assert.assertTrue("parser value is not an integer",data.get("line_integer") instanceof Integer); String lineLong = "9223372036854775806"; System.out.println("line Long :: " + lineLong); data = parser.parse("line_long", lineLong); Assert.assertNotNull("parser result is null", data); Assert.assertEquals("parser size result is incorrect", 1, data.size()); Assert.assertTrue("parser value is not a long",data.get("line_long") instanceof Long); }