This repository has been archived by the owner on Jun 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Id field was not parsed when placed before the type field.
This fix makes sure the id field is parsed when present before the type field by using the buffer parser.
- Loading branch information
1 parent
5c53faf
commit 9809683
Showing
4 changed files
with
78 additions
and
11 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package org.emfjson.jackson.junit.tests; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import org.eclipse.emf.ecore.resource.Resource; | ||
import org.emfjson.jackson.JacksonOptions; | ||
import org.emfjson.jackson.junit.model.ModelFactory; | ||
import org.emfjson.jackson.junit.model.User; | ||
import org.emfjson.jackson.junit.support.TestSupport; | ||
import org.emfjson.jackson.resource.JsonResource; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class IdTest extends TestSupport { | ||
|
||
final JacksonOptions options = new JacksonOptions.Builder() | ||
.withID(true) | ||
.build(); | ||
|
||
@Test | ||
public void testWriteId() { | ||
JsonNode expected = mapper.createObjectNode() | ||
.put("eClass", "http://www.emfjson.org/jackson/model#//User") | ||
.put("_id", "1") | ||
.put("name", "Joe"); | ||
|
||
JsonResource resource = new JsonResource(); | ||
User user = ModelFactory.eINSTANCE.createUser(); | ||
user.setName("Joe"); | ||
resource.setID(user, "1"); | ||
resource.getContents().add(user); | ||
|
||
assertEquals(expected, mapper(options).valueToTree(resource)); | ||
} | ||
|
||
@Test | ||
public void testReadId() throws JsonProcessingException { | ||
JsonNode data = mapper.createObjectNode() | ||
.put("eClass", "http://www.emfjson.org/jackson/model#//User") | ||
.put("_id", "1") | ||
.put("name", "Joe"); | ||
|
||
JsonResource resource = (JsonResource) mapper(options).treeToValue(data, Resource.class); | ||
User user = (User) resource.getContents().get(0); | ||
|
||
assertEquals("1", resource.getID(user)); | ||
} | ||
|
||
@Test | ||
public void testReadId_WhenIdBeforeTypeField() throws JsonProcessingException { | ||
JsonNode data = mapper.createObjectNode() | ||
.put("_id", "1") | ||
.put("eClass", "http://www.emfjson.org/jackson/model#//User") | ||
.put("name", "Joe"); | ||
|
||
JsonResource resource = (JsonResource) mapper(options).treeToValue(data, Resource.class); | ||
User user = (User) resource.getContents().get(0); | ||
|
||
assertEquals("1", resource.getID(user)); | ||
} | ||
|
||
} |
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