Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.github.jasminb.jsonapi.annotations.Relationship;
import com.github.jasminb.jsonapi.annotations.Type;
import com.github.jasminb.jsonapi.exceptions.DocumentSerializationException;
import com.github.jasminb.jsonapi.exceptions.InvalidMetaDataTypeException;
import com.github.jasminb.jsonapi.exceptions.UnregisteredTypeException;
import com.github.jasminb.jsonapi.models.errors.Error;

Expand Down Expand Up @@ -1026,10 +1027,9 @@ private Map<String, Link> mapLinks(JsonNode linksObject) {
try {
return objectMapper.readValue(p, mapType);
} catch (IOException e) {
// TODO: log? No recovery.
e.printStackTrace();
throw new InvalidMetaDataTypeException();
}

return null;
}

private ObjectNode addIncludedSection(ObjectNode rootNode, Map<String, ObjectNode> includedDataMap) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.github.jasminb.jsonapi.exceptions;

/**
* InvalidMetaDataTypeException implementation. <br/>
* This exception is thrown when a <a href="http://jsonapi.org/format/#document-meta">JSON-API meta object</a>
* that is provided is not a {@code Map}. It may be an array instead of a type that can be de-serialized
* to a {@code Map}.
*
* @author ianrumac.
*/

public class InvalidMetaDataTypeException extends RuntimeException {

/**
* Creates a new InvalidMetaDataTypeException.
*/
public InvalidMetaDataTypeException() {
super("Failed to parse JSON-API meta object to a Map type.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.github.jasminb.jsonapi.exceptions.DocumentSerializationException;
import com.github.jasminb.jsonapi.exceptions.InvalidJsonApiResourceException;
import com.github.jasminb.jsonapi.exceptions.InvalidMetaDataTypeException;
import com.github.jasminb.jsonapi.exceptions.UnregisteredTypeException;
import com.github.jasminb.jsonapi.models.Article;
import com.github.jasminb.jsonapi.models.Author;
Expand Down Expand Up @@ -678,6 +679,12 @@ public void testReadMetaOnly() {
Assert.assertNotNull(status.getMeta());
}

@Test(expected = InvalidMetaDataTypeException.class)
public void testInvalidMetaData() throws IOException {
InputStream apiResponse = IOUtils.getResource("users-outside-meta-invalid.json");
converter.readDocumentCollection(apiResponse, User.class);
}

@Test
public void testUnregisteredType() throws IOException {
InputStream apiResponse = IOUtils.getResource("un-registered-type.json");
Expand Down
19 changes: 19 additions & 0 deletions src/test/resources/users-outside-meta-invalid.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"meta":[],
"data": [
{
"type": "users",
"id": "1",
"attributes": {
"name": "liz"
}
},
{
"type": "users",
"id": "2",
"attributes": {
"name": "john"
}
}
]
}