Search in sources :

Example 11 with JSONDeserializer

use of org.eclipse.vorto.mapping.engine.decoder.JSONDeserializer in project vorto by eclipse.

the class DataMapperTest method testMappingWithEnum.

@Test
public void testMappingWithEnum() throws Exception {
    IDataMapper mapper = IDataMapper.newBuilder().withSpecification(new SpecWithNestedEnum()).build();
    final String sampleDeviceData = "{\"temperature\" : 20.3 }";
    IPayloadDeserializer deserializer = new JSONDeserializer();
    InfomodelValue mappedOutput = mapper.mapSource(deserializer.deserialize(sampleDeviceData));
    assertEquals(20.3, mappedOutput.get("outdoorTemperature").getStatusProperty("value").get().getValue());
    assertEquals("Celcius", mappedOutput.get("outdoorTemperature").getStatusProperty("unit").get().getValue());
}
Also used : SpecWithNestedEnum(org.eclipse.vorto.service.mapping.spec.SpecWithNestedEnum) IPayloadDeserializer(org.eclipse.vorto.mapping.engine.decoder.IPayloadDeserializer) IDataMapper(org.eclipse.vorto.mapping.engine.IDataMapper) JSONDeserializer(org.eclipse.vorto.mapping.engine.decoder.JSONDeserializer) InfomodelValue(org.eclipse.vorto.model.runtime.InfomodelValue) Test(org.junit.Test)

Aggregations

JSONDeserializer (org.eclipse.vorto.mapping.engine.decoder.JSONDeserializer)11 InfomodelValue (org.eclipse.vorto.model.runtime.InfomodelValue)10 Test (org.junit.Test)10 IDataMapper (org.eclipse.vorto.mapping.engine.IDataMapper)9 IPayloadDeserializer (org.eclipse.vorto.mapping.engine.decoder.IPayloadDeserializer)9 EntityPropertyValue (org.eclipse.vorto.model.runtime.EntityPropertyValue)3 FunctionblockValue (org.eclipse.vorto.model.runtime.FunctionblockValue)3 IMappingSpecification (org.eclipse.vorto.mapping.engine.model.spec.IMappingSpecification)2 SpecWithNestedEntity (org.eclipse.vorto.service.mapping.spec.SpecWithNestedEntity)2 Date (java.util.Date)1 JavascriptEvalProvider (org.eclipse.vorto.mapping.engine.converter.JavascriptEvalProvider)1 SpecWithTimestamp (org.eclipse.vorto.mapping.engine.converter.date.SpecWithTimestamp)1 SpecWithCustomFunction (org.eclipse.vorto.mapping.engine.converter.javascript.SpecWithCustomFunction)1 SpecWithArrayPayload (org.eclipse.vorto.service.mapping.spec.SpecWithArrayPayload)1 SpecWithConditionalProperties (org.eclipse.vorto.service.mapping.spec.SpecWithConditionalProperties)1 SpecWithConditionedRules (org.eclipse.vorto.service.mapping.spec.SpecWithConditionedRules)1 SpecWithNestedEnum (org.eclipse.vorto.service.mapping.spec.SpecWithNestedEnum)1 SpecWithPropertyConditionXpath (org.eclipse.vorto.service.mapping.spec.SpecWithPropertyConditionXpath)1 SpecWithSameFunctionblock (org.eclipse.vorto.service.mapping.spec.SpecWithSameFunctionblock)1 SpecWithTwoFunctionblocksWithNestedEntity (org.eclipse.vorto.service.mapping.spec.SpecWithTwoFunctionblocksWithNestedEntity)1