5
5
import cz .cvut .kbss .jsonld .deserialization .DeserializationContext ;
6
6
import cz .cvut .kbss .jsonld .deserialization .ValueDeserializer ;
7
7
import cz .cvut .kbss .jsonld .exception .JsonLdDeserializationException ;
8
+ import jakarta .json .JsonNumber ;
9
+ import jakarta .json .JsonValue ;
8
10
9
11
import java .time .OffsetDateTime ;
10
- import java .util .Map ;
11
12
12
13
/**
13
14
* Deserializes values to {@link OffsetDateTime}.
@@ -25,23 +26,22 @@ public class OffsetDateTimeDeserializer implements ValueDeserializer<OffsetDateT
25
26
private final EpochBasedDateTimeResolver epochResolver = new EpochBasedDateTimeResolver ();
26
27
27
28
@ Override
28
- public OffsetDateTime deserialize (Map <?, ?> jsonNode , DeserializationContext <OffsetDateTime > ctx ) {
29
- final Object value = getLiteralValue (jsonNode );
29
+ public OffsetDateTime deserialize (JsonValue jsonNode , DeserializationContext <OffsetDateTime > ctx ) {
30
+ final JsonValue value = getLiteralValue (jsonNode );
30
31
try {
31
- return value instanceof Long ? epochResolver .resolve ((Long ) value ) :
32
+ return value . getValueType () == JsonValue . ValueType . NUMBER ? epochResolver .resolve ((JsonNumber ) value ) :
32
33
stringResolver .resolve (value .toString ());
33
34
} catch (RuntimeException e ) {
34
35
throw new JsonLdDeserializationException ("Unable to deserialize datetime value." , e );
35
36
}
36
37
}
37
38
38
- static Object getLiteralValue (Map <?, ?> jsonNode ) {
39
- final Object value = jsonNode .get (JsonLd .VALUE );
40
- if (value == null ) {
39
+ static JsonValue getLiteralValue (JsonValue jsonNode ) {
40
+ if (jsonNode .getValueType () != JsonValue .ValueType .OBJECT || !jsonNode .asJsonObject ().containsKey (JsonLd .VALUE )) {
41
41
throw new JsonLdDeserializationException ("Cannot deserialize node " + jsonNode + "as literal. " +
42
42
"It is missing attribute '" + JsonLd .VALUE + "'." );
43
43
}
44
- return value ;
44
+ return jsonNode . asJsonObject (). get ( JsonLd . VALUE ) ;
45
45
}
46
46
47
47
@ Override
0 commit comments