-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #424 from taswartz/fix-rest-extra-property-error
Fixing Rest Mapping failures when an extra property is included as a sibling to the root JSON element
- Loading branch information
Showing
6 changed files
with
310 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
239 changes: 120 additions & 119 deletions
239
src/main/java/com/bullhornsdk/data/api/StandardBullhornData.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/main/java/com/bullhornsdk/data/model/response/single/StandardFileContentWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.bullhornsdk.data.model.response.single; | ||
|
||
import com.bullhornsdk.data.model.response.file.standard.StandardFileContent; | ||
import com.fasterxml.jackson.annotation.JsonAnyGetter; | ||
import com.fasterxml.jackson.annotation.JsonAnySetter; | ||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.annotation.JsonPropertyOrder; | ||
|
||
import javax.annotation.Generated; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
@Generated("com.googlecode.jsonschema2pojo") | ||
@JsonPropertyOrder({ "File" }) | ||
public class StandardFileContentWrapper { | ||
|
||
@JsonProperty("File") | ||
private StandardFileContent file; | ||
|
||
private Map<String, Object> additionalProperties = new HashMap<String, Object>(); | ||
|
||
@JsonProperty("File") | ||
public StandardFileContent getFile() { | ||
return this.file; | ||
} | ||
|
||
@JsonProperty("File") | ||
public void setFile(StandardFileContent file) { | ||
this.file = file; | ||
} | ||
|
||
@JsonAnyGetter | ||
public Map<String, Object> getAdditionalProperties() { | ||
return this.additionalProperties; | ||
} | ||
|
||
@JsonAnySetter | ||
public void setAdditionalProperties(String name, Object value) { | ||
this.additionalProperties.put(name, value); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
StringBuilder builder = new StringBuilder(); | ||
builder.append("Wrapper {\ndata="); | ||
builder.append(file); | ||
builder.append(", \nadditionalProperties="); | ||
builder.append(additionalProperties); | ||
builder.append("\n}"); | ||
return builder.toString(); | ||
} | ||
} |
116 changes: 116 additions & 0 deletions
116
src/test/java/com/bullhornsdk/data/api/helper/RestJsonConverterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package com.bullhornsdk.data.api.helper; | ||
|
||
import com.bullhornsdk.data.exception.RestMappingException; | ||
import com.bullhornsdk.data.model.entity.core.standard.JobSubmission; | ||
import com.bullhornsdk.data.model.enums.BullhornEntityInfo; | ||
import com.bullhornsdk.data.model.response.file.standard.StandardFileContent; | ||
import com.bullhornsdk.data.model.response.list.ListWrapper; | ||
import com.bullhornsdk.data.model.response.single.StandardFileContentWrapper; | ||
import com.bullhornsdk.data.model.response.single.StandardWrapper; | ||
import com.bullhornsdk.data.model.response.single.Wrapper; | ||
import org.junit.Test; | ||
|
||
import java.util.List; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
|
||
public class RestJsonConverterTest { | ||
RestJsonConverter restJsonConverter = new RestJsonConverter(); | ||
|
||
private final String singleEntityJson = "{ \"data\": { \"id\": 1, \"status\":\"Approved\" }}"; | ||
|
||
private final String singleEntityJsonExtraProp = "{ " + | ||
"\"total\": 1, " + | ||
"\"data\": { \"id\": 1, \"status\":\"Approved\" }}"; | ||
|
||
private final String multipleEntityJson = "{ " + | ||
"\"data\": [" + | ||
"{ \"id\": 1, \"status\":\"Approved\" }, " + | ||
"{ \"id\": 2, \"status\":\"Not Submitted\" }" + | ||
"]}"; | ||
|
||
private final String multipleEntityJsonExtraProp = "{ " + | ||
"\"total\": 2, " + | ||
"\"data\": [" + | ||
"{ \"id\": 1, \"status\":\"Approved\" }, " + | ||
"{ \"id\": 2, \"status\":\"Not Submitted\" }" + | ||
"]}"; | ||
|
||
private final String standardFileContentJson = "{ " + | ||
"\"File\": { \"fileContent\": \"SomeContent\", \"name\":\"FileName\" }}"; | ||
|
||
private final String standardFileContentJsonExtraProp = "{ " + | ||
"\"total\": 1, " + | ||
"\"File\": { \"fileContent\": \"SomeContent\", \"name\":\"FileName\" }}"; | ||
|
||
@Test | ||
public void jsonToEntityTest() { | ||
Wrapper<JobSubmission> jobSubmissionWrapper = this.restJsonConverter.jsonToEntity(this.singleEntityJson, BullhornEntityInfo.getTypesWrapperType(JobSubmission.class)); | ||
assertNotNull(jobSubmissionWrapper); | ||
assertNotNull(jobSubmissionWrapper.getData()); | ||
assertEquals(jobSubmissionWrapper.getData().getId(), new Integer(1)); | ||
assertEquals(jobSubmissionWrapper.getData().getStatus(), "Approved"); | ||
} | ||
|
||
@Test(expected = RestMappingException.class) | ||
public void jsonToEntityMultipleException() { | ||
this.restJsonConverter.jsonToEntity(this.singleEntityJson, BullhornEntityInfo.getTypesListWrapperType(JobSubmission.class)); | ||
} | ||
|
||
@Test | ||
public void testJsonToEntityWithExtraParentProperty() { | ||
StandardWrapper<JobSubmission> jobSubmissionWrapper = this.restJsonConverter.jsonToEntity(this.singleEntityJsonExtraProp, BullhornEntityInfo.getTypesWrapperType(JobSubmission.class)); | ||
assertNotNull(jobSubmissionWrapper); | ||
assertNotNull(jobSubmissionWrapper.getData()); | ||
assertEquals(new Integer(1), jobSubmissionWrapper.getData().getId()); | ||
assertEquals("Approved", jobSubmissionWrapper.getData().getStatus()); | ||
assertEquals(1, jobSubmissionWrapper.getAdditionalProperties().get("total")); | ||
} | ||
|
||
@Test | ||
public void testJsonListToEntitiesWithExtraParentProperty() { | ||
ListWrapper<JobSubmission> jobSubmissionWrapper = this.restJsonConverter.jsonToEntity(this.multipleEntityJsonExtraProp, BullhornEntityInfo.getTypesListWrapperType(JobSubmission.class)); | ||
assertNotNull(jobSubmissionWrapper); | ||
assertNotNull(jobSubmissionWrapper.getData()); | ||
assertEquals(new Integer(2), jobSubmissionWrapper.getTotal()); | ||
assertEquals(2, jobSubmissionWrapper.getData().size()); | ||
} | ||
|
||
@Test | ||
public void testJsonToMultipleEntity() { | ||
ListWrapper<JobSubmission> jobSubmissionWrapper = this.restJsonConverter.jsonToEntity(this.multipleEntityJson, BullhornEntityInfo.getTypesListWrapperType(JobSubmission.class)); | ||
assertNotNull(jobSubmissionWrapper); | ||
assertNotNull(jobSubmissionWrapper.getData()); | ||
List<JobSubmission> jobSubmissionList = jobSubmissionWrapper.getData(); | ||
assertEquals(new Integer(1), jobSubmissionList.get(0).getId()); | ||
assertEquals("Approved", jobSubmissionList.get(0).getStatus()); | ||
assertEquals(new Integer(2), jobSubmissionList.get(1).getId()); | ||
assertEquals("Not Submitted", jobSubmissionList.get(1).getStatus()); | ||
} | ||
|
||
@Test(expected = RestMappingException.class) | ||
public void testJsonToMultipleEntityWithSingleDataWrapper() { | ||
this.restJsonConverter.jsonToEntity(this.multipleEntityJson, BullhornEntityInfo.getTypesWrapperType(JobSubmission.class)); | ||
} | ||
|
||
@Test | ||
public void testStandardFileContent() { | ||
StandardFileContentWrapper wrapper = this.restJsonConverter.jsonToEntity(this.standardFileContentJson, StandardFileContentWrapper.class); | ||
assertNotNull(wrapper); | ||
assertNotNull(wrapper.getFile()); | ||
StandardFileContent file = wrapper.getFile(); | ||
assertEquals("SomeContent", file.getFileContent()); | ||
assertEquals("FileName", file.getName()); | ||
} | ||
|
||
@Test | ||
public void testStandardFileContentWithExtraProp() { | ||
StandardFileContentWrapper wrapper = this.restJsonConverter.jsonToEntity(this.standardFileContentJsonExtraProp, StandardFileContentWrapper.class); | ||
assertNotNull(wrapper); | ||
assertNotNull(wrapper.getFile()); | ||
StandardFileContent file = wrapper.getFile(); | ||
assertEquals("SomeContent", file.getFileContent()); | ||
assertEquals("FileName", file.getName()); | ||
} | ||
} |