Skip to content

Issue when serializing classes #378

@MattAltermatt

Description

@MattAltermatt

Example is below, this gist of it is that when serializing a class the '}' is missing, which causes incorrect json and issues when later deserializing.

`
@test
public void testClassSerialization(){
String json = Boon.toJson(new MyModel(new KeyValueFinderImpl(), 100));
puts(json);
// Missing the '}' after 'KeyValueFinderImpl"'
//{"keyValueFinder":{"class":"org.boon.json.JsonParserAndMapperBaseTest$KeyValueFinderImpl","size":100}

    MyModel myModel = Boon.fromJson(json, MyModel.class);
    puts(myModel.getSize()); // returns 0, should be 100

    // manually placing the }
    String correctJson = "{\"keyValueFinder\":{\"class\":\"org.boon.json.JsonParserAndMapperBaseTest$KeyValueFinderImpl\"},\"size\":100}";

    myModel = Boon.fromJson(correctJson, MyModel.class);
    puts(myModel.getSize()); // returns 100 now
}

public static class MyModel {
    private KeyValueFinder keyValueFinder;
    private int size;

    public MyModel() {
    }

    public MyModel(KeyValueFinder keyValueFinder, int size) {
        this.keyValueFinder = keyValueFinder;
        this.size = size;
    }

    public KeyValueFinder getKeyValueFinder() {
        return keyValueFinder;
    }

    public void setKeyValueFinder(KeyValueFinder keyValueFinder) {
        this.keyValueFinder = keyValueFinder;
    }

    public int getSize() {
        return size;
    }

    public void setSize(int size) {
        this.size = size;
    }
}

public interface KeyValueFinder{
    int getValue(String key);
}

public static class KeyValueFinderImpl implements KeyValueFinder{

    @Override
    public int getValue(String key) {
        return key.hashCode();
    }
}

`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions