Skip to content
This repository has been archived by the owner on Jun 26, 2021. It is now read-only.

Commit

Permalink
[#81] attribute with null as value is not checked
Browse files Browse the repository at this point in the history
  • Loading branch information
ghillairet committed Mar 21, 2016
1 parent 31ff0e8 commit c12ce64
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,11 @@ protected EObject doDeserialize(JsonParser jp, EClass defaultType, Deserializati
return postDeserialize(buffer, current, defaultType, ctxt);
}

protected EObject postDeserialize(TokenBuffer buffer,
EObject object,
EClass defaultType,
DeserializationContext ctxt) throws IOException {
protected EObject postDeserialize(
TokenBuffer buffer,
EObject object,
EClass defaultType,
DeserializationContext ctxt) throws IOException {

if (object == null && defaultType == null) {
return null;
Expand Down Expand Up @@ -194,12 +195,13 @@ private EClass findRoot(DeserializationContext ctxt) {
return options.rootElement;
}

private void readFeature(JsonParser jp,
EObject current,
String fieldName,
DeserializationContext ctxt,
Resource resource,
ReferenceEntries entries) throws IOException {
private void readFeature(
JsonParser jp,
EObject current,
String fieldName,
DeserializationContext ctxt,
Resource resource,
ReferenceEntries entries) throws IOException {

final EClass eClass = current.eClass();
final EStructuralFeature feature = cache.getEStructuralFeature(eClass, fieldName);
Expand All @@ -209,7 +211,7 @@ private void readFeature(JsonParser jp,
if (jp.getCurrentToken() == JsonToken.FIELD_NAME) {
jp.nextToken();
}

if (jp.getCurrentToken() == JsonToken.VALUE_NULL) {
return;
}
Expand Down Expand Up @@ -240,12 +242,13 @@ private void readFeature(JsonParser jp,
}

@SuppressWarnings("unchecked")
private void readContainment(JsonParser jp,
EObject owner,
DeserializationContext ctxt,
EReference reference,
Resource resource,
ReferenceEntries entries) throws IOException {
private void readContainment(
JsonParser jp,
EObject owner,
DeserializationContext ctxt,
EReference reference,
Resource resource,
ReferenceEntries entries) throws IOException {

final EClass eType = (EClass) owner.eClass().getFeatureType(reference).getEClassifier();
final Class<?> type = eType.getInstanceClass();
Expand Down Expand Up @@ -303,10 +306,11 @@ private void readContainment(JsonParser jp,
Read the key-values pair of a JSON object and put it in a Map.
*/
@SuppressWarnings("unchecked")
private void readMap(JsonParser jp,
EObject owner,
DeserializationContext ctxt,
EReference reference) throws IOException {
private void readMap(
JsonParser jp,
EObject owner,
DeserializationContext ctxt,
EReference reference) throws IOException {

final Collection map = (Collection) owner.eGet(reference);

Expand Down Expand Up @@ -334,11 +338,12 @@ private void readMap(JsonParser jp,
}
}

private void readReference(JsonParser jp,
EObject owner,
EReference reference,
ReferenceEntries entries,
DeserializationContext context) throws IOException {
private void readReference(
JsonParser jp,
EObject owner,
EReference reference,
ReferenceEntries entries,
DeserializationContext context) throws IOException {

if (jp.getCurrentToken() == JsonToken.START_ARRAY) {
while (jp.nextToken() != JsonToken.END_ARRAY) {
Expand All @@ -349,11 +354,12 @@ private void readReference(JsonParser jp,
}
}

private void readAttribute(JsonParser jp,
EObject owner,
EAttribute attribute,
Resource resource,
DeserializationContext ctxt) throws IOException {
private void readAttribute(
JsonParser jp,
EObject owner,
EAttribute attribute,
Resource resource,
DeserializationContext ctxt) throws IOException {

final EDataType dataType = (EDataType) owner.eClass().getFeatureType(attribute).getEClassifier();
if (dataType == null) {
Expand All @@ -371,12 +377,13 @@ private void readAttribute(JsonParser jp,
}
}

private void readSingleAttribute(JsonParser jp,
EObject owner,
EAttribute attribute,
Resource resource,
EDataType dataType,
DeserializationContext ctxt) throws IOException {
private void readSingleAttribute(
JsonParser jp,
EObject owner,
EAttribute attribute,
Resource resource,
EDataType dataType,
DeserializationContext ctxt) throws IOException {

final Class<?> type = dataType.getInstanceClass();

Expand Down
6 changes: 3 additions & 3 deletions src/test/java/org/emfjson/jackson/junit/TestSuite.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@
*/
package org.emfjson.jackson.junit;

import org.emfjson.jackson.junit.tests.*;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;

import org.emfjson.jackson.junit.tests.*;

@RunWith(Suite.class)
@SuiteClasses({
AnnotationTest.class,
Expand Down Expand Up @@ -44,4 +43,5 @@
ValueTest.class,
NullValueInBetweenTest.class
})
public class TestSuite {}
public class TestSuite {
}

This file was deleted.

38 changes: 38 additions & 0 deletions src/test/java/org/emfjson/jackson/junit/tests/ValueTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.Date;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
Expand Down Expand Up @@ -115,6 +116,43 @@ public void testStringValues() throws IOException {
assertEquals(expected, mapper.valueToTree(resource));
}

@Test
public void testLoadStringValues() throws IOException {
JsonNode data = mapper.createObjectNode()
.put("eClass", "http://www.emfjson.org/jackson/model#//ETypes")
.put("eString", "Hello")
.set("eStrings", mapper.createArrayNode()
.add("Hello")
.add("The")
.add("World"));

Resource resource = resourceSet.createResource(URI.createURI("tests/test.json"));
resource.load(new ByteArrayInputStream(mapper.writeValueAsBytes(data)), null);

EObject root = resource.getContents().get(0);
assertEquals(ModelPackage.Literals.ETYPES, root.eClass());

assertEquals("Hello", ((ETypes) root).getEString());

assertThat(((ETypes) root).getEStrings())
.containsExactly("Hello", "The", "World");
}

@Test
public void testLoadNullValue() throws IOException {
JsonNode data = mapper.createObjectNode()
.put("eClass", "http://www.emfjson.org/jackson/model#//ETypes")
.putNull("eString");

Resource resource = resourceSet.createResource(URI.createURI("tests/test.json"));
resource.load(new ByteArrayInputStream(mapper.writeValueAsBytes(data)), null);

EObject root = resource.getContents().get(0);
assertEquals(ModelPackage.Literals.ETYPES, root.eClass());

assertThat(((ETypes) root).getEString()).isNull();
}

@Test
public void testIntValues() throws IOException {
JsonNode expected = mapper.createObjectNode()
Expand Down
8 changes: 0 additions & 8 deletions src/test/resources/tests/test-load-null-value-in-between.json

This file was deleted.

0 comments on commit c12ce64

Please sign in to comment.