Kann JSON nicht deserialisieren

Bitte aktiviere JavaScript!
Hallo,

ich nutze die Google gson 2.8.2 Library.

Ich möchte eine Klasse als JSON speichern und in einem anderen Proghramm dieses JSON laden und die Klasse dabei erzeugen:

Die Klasse Window die ich übergeben möchte:
Java:
public class Window implements java.io.Serializable {

    Window(String windowName) {
        this.windowName = windowName;
    }

    private static final long serialVersionUID = 1068505166493971108L;

    public String windowName = "Fenster Bezeichnungt";
    public String description = "Fenster Beschreibung";

    public DefaultListModel<Point2D> lstModelRU_RealCoordinate = new DefaultListModel<Point2D>();
    public DefaultListModel<Point2D> lstModelLU_RealCoordinate = new DefaultListModel<Point2D>();
    public DefaultListModel<Point2D> lstModelRD_RealCoordinate = new DefaultListModel<Point2D>();
    public DefaultListModel<Point2D> lstModelLD_RealCoordinate = new DefaultListModel<Point2D>();

    public List<Long> timeStamp_RU = new ArrayList<Long>();
    public List<Long> timeStamp_RD = new ArrayList<Long>();
    public List<Long> timeStamp_LU = new ArrayList<Long>();
    public List<Long> timeStamp_LD = new ArrayList<Long>();

    public transient List<BufferedImage> imagesRU = new ArrayList<BufferedImage>();
    public transient List<BufferedImage> imagesLU = new ArrayList<BufferedImage>();
    public transient List<BufferedImage> imagesRD = new ArrayList<BufferedImage>();
    public transient List<BufferedImage> imagesLD = new ArrayList<BufferedImage>();

    public double windowDirectionView = 90;

    public List<Point2D> plySkySelection_RealCoordinate = new ArrayList<Point2D>();

    @Override
    public String toString() {
        return windowName;
    }

  
}
Serialisieren (heißt das so?):
Java:
String json = gson.toJson(window);
Deserialisieren:
Java:
            GsonBuilder gsonBuilder = new GsonBuilder();
            gsonBuilder.registerTypeAdapter(Point2D.class, new LocationDeserializer());
            gsonBuilder.registerTypeAdapter(Point2D.class, new LocationSerializer());
            Gson gson = gsonBuilder.create();
            Window window = gson.fromJson(skyList, Window.class);


....

class LocationSerializer implements JsonSerializer<Point2D> {
    public JsonElement serialize(Point2D t, Type type, JsonSerializationContext jsc) {
        JsonObject jo = new JsonObject();
        jo.addProperty("mX", t.getX());
        jo.addProperty("mY", t.getY());
        return jo;
    }

}

class LocationDeserializer implements JsonDeserializer<Point2D> {
    public Point2D deserialize(JsonElement je, Type type, JsonDeserializationContext jdc) throws JsonParseException {
        JsonObject jo = je.getAsJsonObject();
        Point2D l;
        if (jo.getAsJsonPrimitive("x") == null || jo.getAsJsonPrimitive("y") == null) {
            l = new Point2D.Double(0, 0);

        } else {
            l = new Point2D.Double(jo.getAsJsonPrimitive("x").getAsDouble(), jo.getAsJsonPrimitive("y").getAsDouble());
        }
        return l;
    }
Und das erzeugte JSON:
JSON:
{"windowName":"Beschattung 1","description":"Fenster Beschreibung","lstModelRU_RealCoordinate":{"delegate":[],"listenerList":{}},"lstModelLU_RealCoordinate":{"delegate":[],"listenerList":{}},"lstModelRD_RealCoordinate":{"delegate":[{"x":349.58,"y":3.99},{"x":349.29,"y":25.78},{"x":369.49,"y":56.99},{"x":462.98,"y":64.67},{"x":472.39,"y":61.97},{"x":471.49,"y":41.47},{"x":472.28,"y":35.68},{"x":466.67,"y":22.79},{"x":467.78,"y":5.88},{"x":436.18,"y":3.38}],"listenerList":{}},"lstModelLD_RealCoordinate":{"delegate":[{"x":392.08,"y":-0.03},{"x":391.68,"y":67.47},{"x":497.68,"y":41.79},{"x":504.99,"y":37.19},{"x":484.67,"y":22.37},{"x":483.68,"y":2.38}],"listenerList":{}},"timeStamp_RU":[],"timeStamp_RD":[1499248275135,1499248279599,1499248286920,1499248301462,1499248308319,1499248312975,1499248321966,1499248329166,1499248333735,1499248337679],"timeStamp_LU":[],"timeStamp_LD":[1499248040207,1499248050720,1499248060663,1499248066391,1499248071736,1499248076343],"windowDirectionView":342.0,"plySkySelection_RealCoordinate":[{"x":392.08,"y":-0.03},{"x":392.0579508716128,"y":3.6907904153385243},{"x":349.58,"y":3.99},{"x":349.29,"y":25.78},{"x":369.49,"y":56.99},{"x":391.73127660764055,"y":58.81707246065547},{"x":391.68,"y":67.47},{"x":418.36563582256537,"y":61.00502709506153},{"x":462.98,"y":64.67},{"x":472.39,"y":61.97},{"x":471.77952588938996,"y":48.064756369438356},{"x":497.68,"y":41.79},{"x":504.99,"y":37.19},{"x":484.67,"y":22.37},{"x":483.68,"y":2.38},{"x":392.08,"y":-0.03}]}
Der Fehler:
Code:
Caused by: java.lang.reflect.MalformedParameterizedTypeException
    at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.validateConstructorArguments(Unknown Source)
    at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.<init>(Unknown Source)
    at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.make(Unknown Source)
    at sun.reflect.generics.factory.CoreReflectionFactory.makeParameterizedType(Unknown Source)
    at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Unknown Source)
    at sun.reflect.generics.tree.ClassTypeSignature.accept(Unknown Source)
    at sun.reflect.generics.repository.FieldRepository.getGenericType(Unknown Source)
    at java.lang.reflect.Field.getGenericType(Unknown Source)
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:158)
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:100)
    at com.google.gson.Gson.getAdapter(Gson.java:423)
    at com.google.gson.Gson.fromJson(Gson.java:887)
    at com.google.gson.Gson.fromJson(Gson.java:853)
    at com.google.gson.Gson.fromJson(Gson.java:802)
    at com.google.gson.Gson.fromJson(Gson.java:774)
    at com.company.Suntracker.onPropertySkyList(Suntracker.java:946)
    ... 9 more
 
A

Anzeige


Vielleicht hilft dir dieser Kurs hier weiter: (hier klicken)
Passende Stellenanzeigen aus deiner Region:

Neue Themen

Oben