Skip to content

Commit

Permalink
removed 8 year old deprecated functions from JSON IO and switched the…
Browse files Browse the repository at this point in the history
… tests to using the new. This triggers several hidden bugs in the "new" API
  • Loading branch information
jurgenvinju committed Dec 18, 2024
1 parent cfc601c commit 94dd242
Show file tree
Hide file tree
Showing 7 changed files with 2 additions and 1,287 deletions.
29 changes: 0 additions & 29 deletions src/org/rascalmpl/library/lang/json/Factory.java

This file was deleted.

48 changes: 0 additions & 48 deletions src/org/rascalmpl/library/lang/json/IO.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import java.util.stream.Collectors;
import org.rascalmpl.debug.IRascalMonitor;
import org.rascalmpl.exceptions.RuntimeExceptionFactory;
import org.rascalmpl.library.lang.json.internal.IValueAdapter;
import org.rascalmpl.library.lang.json.internal.JSONReadingTypeVisitor;
import org.rascalmpl.library.lang.json.internal.JsonValueReader;
import org.rascalmpl.library.lang.json.internal.JsonValueWriter;
import org.rascalmpl.types.ReifiedType;
Expand All @@ -45,13 +43,8 @@
import io.usethesource.vallang.type.Type;
import io.usethesource.vallang.type.TypeStore;

import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import com.ibm.icu.text.DateFormat;

public class IO {
private final IRascalValueFactory values;
Expand All @@ -62,48 +55,7 @@ public IO(IRascalValueFactory values, IRascalMonitor monitor) {
this.values = values;
this.monitor = monitor;
}

public IString toJSON(IValue value) {
return toJSON(value, this.values.bool(false));
}


public IString toJSON(IValue value, IBool compact) {
IValueAdapter adap = new IValueAdapter(compact.getValue());
Gson gson = new GsonBuilder()
.registerTypeAdapter(IValue.class, adap)
.enableComplexMapKeySerialization()
.setDateFormat(DateFormat.LONG)
.setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE)
.setVersion(1.0)
.disableHtmlEscaping()
.create();
try {
String json = gson.toJson(value, new TypeToken<IValue>() {}.getType());
return values.string(json);
} catch (Exception e) {
throw RuntimeExceptionFactory.io(values.string(e.getMessage()), null, null);
}
}

public IValue fromJSON(IValue type, IString src) {
TypeStore store = new TypeStore();
Type start = new TypeReifier(values).valueToType((IConstructor) type, store);
Gson gson = new GsonBuilder()
.enableComplexMapKeySerialization()
.setDateFormat(DateFormat.LONG)
.setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE)
.setVersion(1.0)
.create();
Object obj = gson.fromJson(src.getValue(), Object.class);
try {
return JSONReadingTypeVisitor.read(obj, values, store, start);
}
catch (IOException e) {
throw RuntimeExceptionFactory.io(values.string(e.getMessage()), null, null);
}
}

public IValue readJSON(IValue type, ISourceLocation loc, IString dateTimeFormat, IBool lenient, IBool trackOrigins, IFunction parsers, IMap nulls, IBool explicitConstructorNames, IBool explicitDataTypes) {
TypeStore store = new TypeStore();
Type start = new TypeReifier(values).valueToType((IConstructor) type, store);
Expand Down
15 changes: 0 additions & 15 deletions src/org/rascalmpl/library/lang/json/IO.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,6 @@ import Exception;
}
data RuntimeException(str cause="", str path="");

@javaClass{org.rascalmpl.library.lang.json.IO}
@synopsis{Maps any Rascal value to a JSON string}
@deprecated{use ((writeJSON))}
public java str toJSON(value v);

@javaClass{org.rascalmpl.library.lang.json.IO}
@synopsis{Maps any Rascal value to a JSON string, optionally in compact form.}
@deprecated{use ((asJSON))}
public java str toJSON(value v, bool compact);

@javaClass{org.rascalmpl.library.lang.json.IO}
@deprecated{use ((readJSON))}
@synopsis{Parses a JSON string and maps it to the requested type of Rascal value.}
public java &T fromJSON(type[&T] typ, str src);

@javaClass{org.rascalmpl.library.lang.json.IO}
@synopsis{reads JSON values from a stream}
@description{
Expand Down
27 changes: 0 additions & 27 deletions src/org/rascalmpl/library/lang/json/internal/IValueAdapter.java

This file was deleted.

Loading

0 comments on commit 94dd242

Please sign in to comment.