AMImageSerializerImpl implements AMImageSerializer { @Override public String serialize(AdaptiveMedia<AMImageProcessor> adaptiveMedia) { JSONObject attributesJSONObject = JSONFactoryUtil.createJSONObject(); Map<String, AMAttribute<?, ?>> allowedAMAttributes = AMImageAttribute.getAllowedAMAttributes(); allowedAMAttributes.forEach( (name, amAttribute) -> { Optional<Object> valueOptional = adaptiveMedia.getValueOptional( (AMAttribute)amAttribute); valueOptional.ifPresent( value -> attributesJSONObject.put( name, String.valueOf(value))); }); JSONObject jsonObject = JSONUtil.put( "attributes", attributesJSONObject ).put( "uri", adaptiveMedia.getURI() ); return jsonObject.toString(); }  @Override AdaptiveMedia<AMImageProcessor> deserialize(
		String s, Supplier<InputStream> inputStreamSupplier); @Override String serialize(AdaptiveMedia<AMImageProcessor> adaptiveMedia);  }
@Test public void testSerialize() throws Exception { AdaptiveMedia<AMImageProcessor> adaptiveMedia = new AMImage( () -> null, AMImageAttributeMapping.fromProperties( HashMapBuilder.put( AMImageAttribute.AM_IMAGE_ATTRIBUTE_HEIGHT.getName(), "200" ).put( AMImageAttribute.AM_IMAGE_ATTRIBUTE_WIDTH.getName(), "300" ).build()), new URI("http: AMImageSerializer amImageSerializer = new AMImageSerializerImpl(); String serialize = amImageSerializer.serialize(adaptiveMedia); JSONObject jsonObject = JSONFactoryUtil.createJSONObject(serialize); Assert.assertEquals("http: JSONObject attributesJSONObject = jsonObject.getJSONObject( "attributes"); Assert.assertEquals( "200", attributesJSONObject.getString( AMImageAttribute.AM_IMAGE_ATTRIBUTE_HEIGHT.getName())); Assert.assertEquals( "300", attributesJSONObject.getString( AMImageAttribute.AM_IMAGE_ATTRIBUTE_WIDTH.getName())); AMAttribute<?, Long> contentLengthAMAttribute = AMAttribute.getContentLengthAMAttribute(); Assert.assertEquals( StringPool.BLANK, attributesJSONObject.getString(contentLengthAMAttribute.getName())); }
@Test public void testSerializeAdaptiveMediaWithEmptyAttributes() throws Exception { Map<String, String> properties = new HashMap<>(); AdaptiveMedia<AMImageProcessor> adaptiveMedia = new AMImage( () -> null, AMImageAttributeMapping.fromProperties(properties), new URI("http: AMImageSerializer amImageSerializer = new AMImageSerializerImpl(); String serialize = amImageSerializer.serialize(adaptiveMedia); JSONObject jsonObject = JSONFactoryUtil.createJSONObject(serialize); JSONObject attributesJSONObject = jsonObject.getJSONObject( "attributes"); Assert.assertEquals(0, attributesJSONObject.length()); }