diff --git a/src/org/rascalmpl/library/lang/json/internal/JsonValueWriter.java b/src/org/rascalmpl/library/lang/json/internal/JsonValueWriter.java index e836f63576..68830ddf99 100644 --- a/src/org/rascalmpl/library/lang/json/internal/JsonValueWriter.java +++ b/src/org/rascalmpl/library/lang/json/internal/JsonValueWriter.java @@ -126,8 +126,8 @@ public Void visitReal(IReal o) throws IOException { @Override public Void visitRational(IRational o) throws IOException { out.beginArray(); - out.value(o.numerator().getStringRepresentation()); - out.value(o.denominator().getStringRepresentation()); + out.value(o.numerator().longValue()); + out.value(o.denominator().longValue()); out.endArray(); return null; diff --git a/src/org/rascalmpl/library/lang/rascal/tests/library/lang/json/JSONIOTests.rsc b/src/org/rascalmpl/library/lang/rascal/tests/library/lang/json/JSONIOTests.rsc index cbc86face5..8c4bebe763 100644 --- a/src/org/rascalmpl/library/lang/rascal/tests/library/lang/json/JSONIOTests.rsc +++ b/src/org/rascalmpl/library/lang/rascal/tests/library/lang/json/JSONIOTests.rsc @@ -8,6 +8,7 @@ import IO; import util::Math; import Type; import DateTime; +import List; loc targetFile = |memory://test-tmp/test-<"">.json|; @@ -88,23 +89,26 @@ default value numNormalizer(value x) = x; @synopsis{Normalizer used to replace unrecoverable types with their default representatives} -value toDefaultRec(value readBack) = visit(readBack) { +value toDefaultRec(value readBack) = visit(readBack) { case value x => toDefaultValue(x) }; -value toDefaultValue(rat r) = ["", ""]; -value toDefaultValue(set[value] x) = [*x]; +// this list order depends on the hashcodes of the children +// as the writer is top-down and this rewrite is bottom-up +// we end up with different lists sometimes (if the elements have been rewritten). +value toDefaultValue(set[value] x) = [*x]; + value toDefaultValue(map[void,void] _) = "object"(); value toDefaultValue(<>) = []; -value toDefaultValue() = [x]; -value toDefaultValue() = [x,y]; -value toDefaultValue() = [x,y,z]; -value toDefaultValue() = [x,y,z,a]; -value toDefaultValue() = [x,y,z,a,b]; -value toDefaultValue() = [x,y,z,a,b,c]; -value toDefaultValue() = [x,y,z,a,b,c,d]; -value toDefaultValue() = [x,y,z,a,b,c,d,e]; -value toDefaultValue() = [x,y,z,a,b,c,d,e,f]; +value toDefaultValue() = [x]; +value toDefaultValue() = [x,y]; +value toDefaultValue() = [x,y,z]; +value toDefaultValue() = [x,y,z,a]; +value toDefaultValue() = [x,y,z,a,b]; +value toDefaultValue() = [x,y,z,a,b,c]; +value toDefaultValue() = [x,y,z,a,b,c,d]; +value toDefaultValue() = [x,y,z,a,b,c,d,e]; +value toDefaultValue() = [x,y,z,a,b,c,d,e,f]; value toDefaultValue(loc l) { // this simulates the simplications the writer applies if (!(l.offset?)) { @@ -120,6 +124,7 @@ value toDefaultValue(loc l) { } } +value toDefaultValue(rat r) = [numerator(r), denominator(r)]; value toDefaultValue(datetime t) = printDateTime(t, "yyyy-MM-dd\'T\'HH:mm:ssZ"); value toDefaultValue(real r) = round(r) when r - round(r) == 0; default value toDefaultValue(value x) = x;