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

Conflicting fields #67

Open
adrienbrunJP opened this issue Jul 13, 2018 · 1 comment
Open

Conflicting fields #67

adrienbrunJP opened this issue Jul 13, 2018 · 1 comment

Comments

@adrienbrunJP
Copy link

Hi,

I used you example in LazyAdaptersRetrofitTest but ended up with the following issue: if 'item' or 'item2' in the test "unwrapNestedJsonAdapter" contain more than one element, then in the "Nested" class you have to do something like:

 @Json(name = "item") @Wrapped(path = "foo1") String foo1;
 @Json(name = "item") @Wrapped(path = "foo2") String foo2;

But then you get an exception from Moshi saying there are conflicting fields because of the 2 "item".
Am I missing something ?

@serj-lotutovici
Copy link
Owner

Sorry for the late reply. Somehow I missed this in my notifications.
This will not work since moshi consumes the json field as soon as it's parsed.

You can probably work around this, by creating your own WrappedJsonAdapter that will leverage from this https://github.com/square/moshi/blob/master/moshi/src/main/java/com/squareup/moshi/JsonReader.java#L420. The idea would be to first read the full json that contains the field item with readJsonValue() (essentially buffering everything in a map) and then parsing it twice. I didn't try it my self, and not 100% sure if that will work, but it may work.

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

2 participants