File tree Expand file tree Collapse file tree
main/java/com/github/jsonldjava/core
test/java/com/github/jsonldjava/core Expand file tree Collapse file tree Original file line number Diff line number Diff line change 66import static com .github .jsonldjava .core .JsonLdConsts .RDF_REST ;
77import static com .github .jsonldjava .core .JsonLdConsts .RDF_TYPE ;
88import static com .github .jsonldjava .core .JsonLdConsts .XSD_BOOLEAN ;
9+ import static com .github .jsonldjava .core .JsonLdConsts .XSD_DECIMAL ;
910import static com .github .jsonldjava .core .JsonLdConsts .XSD_DOUBLE ;
1011import static com .github .jsonldjava .core .JsonLdConsts .XSD_INTEGER ;
1112import static com .github .jsonldjava .core .JsonLdConsts .XSD_STRING ;
@@ -665,7 +666,10 @@ private Node objectToRDF(Object item) {
665666 return new Literal (Float .toString ((float ) value ),
666667 datatype == null ? XSD_DOUBLE : (String ) datatype , null );
667668 } else {
668- // canonical double representation
669+ // Only canonicalize representation if datatype is not XSD_DECIMAL
670+ if (XSD_DECIMAL .equals (datatype )) {
671+ return new Literal (value .toString (), XSD_DECIMAL , null );
672+ }
669673 final DecimalFormat df = new DecimalFormat ("0.0###############E0" );
670674 df .setDecimalFormatSymbols (DecimalFormatSymbols .getInstance (Locale .US ));
671675 return new Literal (df .format (value ),
Original file line number Diff line number Diff line change 1+ package com .github .jsonldjava .core ;
2+
3+ import org .junit .Test ;
4+
5+ import java .util .HashMap ;
6+ import java .util .List ;
7+ import java .util .Map ;
8+
9+ import static org .junit .Assert .assertEquals ;
10+
11+ public class DecimalLiteralCanonicalTest {
12+
13+ @ Test
14+ public void testDecimalIsNotCanonicalized () {
15+ double value = 6.5 ;
16+
17+ Map <String , Object > innerMap = new HashMap <>();
18+ innerMap .put ("@value" , value );
19+ innerMap .put ("@type" , "http://www.w3.org/2001/XMLSchema#decimal" );
20+
21+ Map <String , Object > jsonMap = new HashMap <>();
22+ jsonMap .put ("ex:id" , innerMap );
23+
24+ JsonLdApi api = new JsonLdApi (jsonMap , new JsonLdOptions ("" ));
25+ RDFDataset dataset = api .toRDF ();
26+
27+ List <Object > defaultList = (List <Object >) dataset .get ("@default" );
28+ Map <String , Object > tripleMap = (Map <String , Object >) defaultList .get (0 );
29+ Map <String , String > objectMap = (Map <String , String >) tripleMap .get ("object" );
30+
31+ assertEquals ("http://www.w3.org/2001/XMLSchema#decimal" , objectMap .get ("datatype" ));
32+ assertEquals (Double .toString (value ), objectMap .get ("value" ));
33+ }
34+ }
You can’t perform that action at this time.
0 commit comments