Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue when serializing classes #378

Open
MattAltermatt opened this issue Jul 12, 2017 · 0 comments
Open

Issue when serializing classes #378

MattAltermatt opened this issue Jul 12, 2017 · 0 comments

Comments

@MattAltermatt
Copy link

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();
    }
}

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant