Search in sources :

Example 1 with ValueFormatException

use of de.fraunhofer.iosb.ilt.faaast.service.model.value.primitive.ValueFormatException in project FAAAST-Service by FraunhoferIOSB.

the class RangeValueMapper method toValue.

@Override
public RangeValue toValue(Range submodelElement) {
    if (submodelElement == null) {
        return null;
    }
    RangeValue rangeValue = new RangeValue();
    try {
        rangeValue.setMin(TypedValueFactory.create(submodelElement.getValueType(), submodelElement.getMin()));
        rangeValue.setMax(TypedValueFactory.create(submodelElement.getValueType(), submodelElement.getMax()));
    } catch (ValueFormatException ex) {
        // TODO properly throw?
        throw new RuntimeException("invalid data value");
    }
    return rangeValue;
}
Also used : ValueFormatException(de.fraunhofer.iosb.ilt.faaast.service.model.value.primitive.ValueFormatException) RangeValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.RangeValue)

Example 2 with ValueFormatException

use of de.fraunhofer.iosb.ilt.faaast.service.model.value.primitive.ValueFormatException in project FAAAST-Service by FraunhoferIOSB.

the class TypedValueDeserializer method deserialize.

@Override
public TypedValue deserialize(JsonParser parser, DeserializationContext context) throws IOException, JacksonException {
    TypeInfo typeInfo = ContextAwareElementValueDeserializer.getTypeInfo(context);
    if (typeInfo == null || !ElementValueTypeInfo.class.isAssignableFrom(typeInfo.getClass())) {
        throw new RuntimeException("missing datatype information");
    }
    Datatype datatype = ((ElementValueTypeInfo) typeInfo).getDatatype();
    try {
        return TypedValueFactory.create(datatype, parser.getValueAsString());
    } catch (ValueFormatException ex) {
        throw new IOException(String.format("error deserializing typed value (datatype: %s, value %s", datatype.getName(), parser.getValueAsString()), ex);
    }
}
Also used : ElementValueTypeInfo(de.fraunhofer.iosb.ilt.faaast.service.typing.ElementValueTypeInfo) ValueFormatException(de.fraunhofer.iosb.ilt.faaast.service.model.value.primitive.ValueFormatException) IOException(java.io.IOException) ElementValueTypeInfo(de.fraunhofer.iosb.ilt.faaast.service.typing.ElementValueTypeInfo) TypeInfo(de.fraunhofer.iosb.ilt.faaast.service.typing.TypeInfo) Datatype(de.fraunhofer.iosb.ilt.faaast.service.model.value.primitive.Datatype)

Aggregations

ValueFormatException (de.fraunhofer.iosb.ilt.faaast.service.model.value.primitive.ValueFormatException)2 RangeValue (de.fraunhofer.iosb.ilt.faaast.service.model.value.RangeValue)1 Datatype (de.fraunhofer.iosb.ilt.faaast.service.model.value.primitive.Datatype)1 ElementValueTypeInfo (de.fraunhofer.iosb.ilt.faaast.service.typing.ElementValueTypeInfo)1 TypeInfo (de.fraunhofer.iosb.ilt.faaast.service.typing.TypeInfo)1 IOException (java.io.IOException)1