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

Inconsistent behavior of from/toJson-methods when dealing with JsonObject or JsonArray #24

Closed
jklingsporn opened this issue Nov 10, 2017 · 1 comment
Assignees
Labels
Milestone

Comments

@jklingsporn
Copy link
Owner

Looking at the following methods from a generated POJO

default ISomething fromJson(io.vertx.core.json.JsonObject json) {
        setSomeid(json.getInteger("someid"));
        setSomestring(json.getString("somestring"));
        setSomehugenumber(json.getLong("somehugenumber"));
        setSomesmallnumber(json.getInteger("somesmallnumber")==null?null:json.getInteger("somesmallnumber").shortValue());
        setSomeregularnumber(json.getInteger("someregularnumber"));
        setSomeboolean(json.getBoolean("someboolean"));
        setSomedouble(json.getDouble("somedouble"));
        setSomejsonobject(new io.github.jklingsporn.vertx.jooq.shared.JsonObjectConverter().from(json.getString("somejsonobject")));
        setSomejsonarray(new io.github.jklingsporn.vertx.jooq.shared.JsonArrayConverter().from(json.getString("somejsonarray")));
        return this;
    }


    default io.vertx.core.json.JsonObject toJson() {
        io.vertx.core.json.JsonObject json = new io.vertx.core.json.JsonObject();
        json.put("someid",getSomeid());
        json.put("somestring",getSomestring());
        json.put("somehugenumber",getSomehugenumber());
        json.put("somesmallnumber",getSomesmallnumber());
        json.put("someregularnumber",getSomeregularnumber());
        json.put("someboolean",getSomeboolean());
        json.put("somedouble",getSomedouble());
        json.put("somejsonobject",getSomejsonobject());
        json.put("somejsonarray",getSomejsonarray());
        return json;
    }

In this case, the fields somejsonobject or somejsonarray are converted using the JsonObjectConverter or JsonArrayConverter. That is done on a jOOQ-level. There is no need to convert them again in the fromJson-method (actually that fails with a ClassCastException).

@jklingsporn jklingsporn self-assigned this Nov 10, 2017
@jklingsporn
Copy link
Owner Author

Also one would expect that the following would work:

Something something = new Something(/*some values*);
JsonObject somethingJson = something.toJson();
Something sameSomething = new Something(somethingJson);
Assert.assertEquals(something,sameSomething);

jklingsporn pushed a commit that referenced this issue Nov 10, 2017

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
…aling with JsonObject or JsonArray
@jklingsporn jklingsporn added this to the 2.4.0 milestone Nov 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant