JsonHandler extends HandlerBase { protected JsonObjectBuilder showMapProperty(Property property) { JsonObjectBuilder propBuilder = Json.createObjectBuilder(); JsonObjectBuilder lPropBuilder = Json.createObjectBuilder(); Map<?, ?> propMap = (Map<?, ?>) property.getValue(); PropertyType type = property.getType(); Iterator<?> keyIter = propMap.keySet().iterator(); while (keyIter.hasNext()) { Object key = keyIter.next(); String keystr = key.toString(); Object val = propMap.get(key); switch (type) { case BOOLEAN: lPropBuilder.add(keystr, ((Boolean) val).booleanValue()); break; case BYTE: lPropBuilder.add(keystr, valueToString(val)); break; case CHARACTER: lPropBuilder.add(keystr, valueToString(val)); break; case DATE: lPropBuilder.add(keystr, valueToString(val)); break; case DOUBLE: lPropBuilder.add(keystr, ((Double) val).doubleValue()); break; case FLOAT: lPropBuilder.add(keystr, ((Float) val).floatValue()); break; case INTEGER: lPropBuilder.add(keystr, ((Integer) val).intValue()); break; case LONG: lPropBuilder.add(keystr, ((Long) val).longValue()); break; case OBJECT: lPropBuilder.add(keystr, valueToString(val)); break; case SHORT: lPropBuilder.add(keystr, ((Short) val).shortValue()); break; case STRING: lPropBuilder.add(keystr, valueToString(val)); break; case RATIONAL: lPropBuilder.add(keystr, showRational((Rational) val)); break; case PROPERTY: lPropBuilder.add(keystr, showProperty((Property) val)); break; case NISOIMAGEMETADATA: lPropBuilder.add(keystr, showNisoImageMetadata((NisoImageMetadata) property.getValue())); break; case AESAUDIOMETADATA: lPropBuilder.add(keystr, showAESAudioMetadata((AESAudioMetadata) property.getValue())); break; case TEXTMDMETADATA: lPropBuilder.add(keystr, showTextMDMetadata((TextMDMetadata) property.getValue())); break; default: break; } } propBuilder.add(property.getName(), lPropBuilder); return propBuilder; } JsonHandler();  JsonHandler(String name, String release, int[] date, String note, String rights); @Override void show(); @Override void show(App app); @Override void show(OutputHandler handler); @Override void show(Module module); @Override void show(RepInfo info); @Override void showFooter(); @Override void showHeader();  }
@Test public void testShowMapProperty() throws IOException { final Map<String,String> testMap = Collections.singletonMap("mykey", "myvalue"); Property prop = new Property("test", PropertyType.STRING, PropertyArity.MAP, testMap); JsonObjectBuilder b = this.handler.showMapProperty(prop); buildJson(b); handler.close(); String result = outString.toString(); LOGGER.info(FIND + result); final String expected = "{\"test\":{\"mykey\":\"myvalue\"}}"; assertEquals(expected, result); }