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

com.squareup.moshi.JsonDataException: Unknown type of resource: place_address #104

Open
di0n0s opened this issue Dec 17, 2019 · 1 comment

Comments

@di0n0s
Copy link

di0n0s commented Dec 17, 2019

Hi,

I receive this JSON:

{
	"data": [{
		"type": "place",
		"id": "00d66be8-7315-4f75-9dc1-7dc737a055ef",
		"attributes": {
			"name": "Test Pharmacy",
			"lat": 42.394898,
			"lng": 2.151117,
			"image_url": "",
			"user_distance": 0.03
		},
		"relationships": {
			"place_address": {
				"data": {
					"type": "place_address",
					"id": "00d66be8-7315-4f75-9dc1-7dc737a055ef"
				}
			}
		}
	}, {
		"type": "place",
		"id": "6f781c99-c991-442f-ae14-9630ee475f41",
		"attributes": {
			"name": "Farmacia Test",
			"lat": 42.394898,
			"lng": 2.112117,
			"image_url": "http:\/\/test.test.com\/image.png",
			"user_distance": 0.03
		},
		"relationships": {
			"place_address": {
				"data": {
					"type": "place_address",
					"id": "6f781c99-c991-442f-ae14-9630ee475f41"
				}
			}
		}
	}],
	"included": [{
		"type": "place_address",
		"id": "00d66be8-7315-4f75-9dc1-7dc737a055ef",
		"attributes": {
			"name": "Test Pharmacy Address",
			"country_code": "ES",
			"postal_code": "",
			"city": "",
			"region": "",
			"postal_address_line_one": "",
			"postal_address_line_two": "",
			"phone_number_one": "",
			"phone_number_two": ""
		}
	}, {
		"type": "place_address",
		"id": "6f781c99-c991-442f-ae14-9630ee475f41",
		"attributes": {
			"name": "address",
			"country_code": "ES",
			"postal_code": "",
			"city": "",
			"region": "",
			"postal_address_line_one": "",
			"postal_address_line_two": "",
			"phone_number_one": "",
			"phone_number_two": ""
		}
	}]
}

And I have this resource:

@JsonApi(type = "place")
public class PlaceResponse extends Resource {

    @Json(name = "name")
    public String name;
    @Json(name = "image")
    public String imageUrl;
    @Json(name = "lat")
    public Double latitude;
    @Json(name = "lng")
    public Double longitude;
    @Json(name = "user_distance")
    public Double userDistance;

}

When I'm trying to parse that JSON I got this exception: "com.squareup.moshi.JsonDataException: Unknown type of resource: place_address"

Why I'm getting this exception if I'm not parsing the relationship? Is mandatory to parse every field of the JSON? I hope not.

Thanks in advance.

@Dill-Lan
Copy link

Hey @di0n0s I think this is a duplicate of #71

I ran in to the same problem and found yours and the above issue.
Basically, the answer is to do as described here: https://github.com/kamikat/moshi-jsonapi#default-resource-type

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