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

Commit c12ce64

Browse files
committed
[#81] attribute with null as value is not checked
1 parent 31ff0e8 commit c12ce64

5 files changed

Lines changed: 85 additions & 92 deletions

File tree

src/main/java/org/emfjson/jackson/databind/deser/EObjectDeserializer.java

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,11 @@ protected EObject doDeserialize(JsonParser jp, EClass defaultType, Deserializati
143143
return postDeserialize(buffer, current, defaultType, ctxt);
144144
}
145145

146-
protected EObject postDeserialize(TokenBuffer buffer,
147-
EObject object,
148-
EClass defaultType,
149-
DeserializationContext ctxt) throws IOException {
146+
protected EObject postDeserialize(
147+
TokenBuffer buffer,
148+
EObject object,
149+
EClass defaultType,
150+
DeserializationContext ctxt) throws IOException {
150151

151152
if (object == null && defaultType == null) {
152153
return null;
@@ -194,12 +195,13 @@ private EClass findRoot(DeserializationContext ctxt) {
194195
return options.rootElement;
195196
}
196197

197-
private void readFeature(JsonParser jp,
198-
EObject current,
199-
String fieldName,
200-
DeserializationContext ctxt,
201-
Resource resource,
202-
ReferenceEntries entries) throws IOException {
198+
private void readFeature(
199+
JsonParser jp,
200+
EObject current,
201+
String fieldName,
202+
DeserializationContext ctxt,
203+
Resource resource,
204+
ReferenceEntries entries) throws IOException {
203205

204206
final EClass eClass = current.eClass();
205207
final EStructuralFeature feature = cache.getEStructuralFeature(eClass, fieldName);
@@ -209,7 +211,7 @@ private void readFeature(JsonParser jp,
209211
if (jp.getCurrentToken() == JsonToken.FIELD_NAME) {
210212
jp.nextToken();
211213
}
212-
214+
213215
if (jp.getCurrentToken() == JsonToken.VALUE_NULL) {
214216
return;
215217
}
@@ -240,12 +242,13 @@ private void readFeature(JsonParser jp,
240242
}
241243

242244
@SuppressWarnings("unchecked")
243-
private void readContainment(JsonParser jp,
244-
EObject owner,
245-
DeserializationContext ctxt,
246-
EReference reference,
247-
Resource resource,
248-
ReferenceEntries entries) throws IOException {
245+
private void readContainment(
246+
JsonParser jp,
247+
EObject owner,
248+
DeserializationContext ctxt,
249+
EReference reference,
250+
Resource resource,
251+
ReferenceEntries entries) throws IOException {
249252

250253
final EClass eType = (EClass) owner.eClass().getFeatureType(reference).getEClassifier();
251254
final Class<?> type = eType.getInstanceClass();
@@ -303,10 +306,11 @@ private void readContainment(JsonParser jp,
303306
Read the key-values pair of a JSON object and put it in a Map.
304307
*/
305308
@SuppressWarnings("unchecked")
306-
private void readMap(JsonParser jp,
307-
EObject owner,
308-
DeserializationContext ctxt,
309-
EReference reference) throws IOException {
309+
private void readMap(
310+
JsonParser jp,
311+
EObject owner,
312+
DeserializationContext ctxt,
313+
EReference reference) throws IOException {
310314

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

@@ -334,11 +338,12 @@ private void readMap(JsonParser jp,
334338
}
335339
}
336340

337-
private void readReference(JsonParser jp,
338-
EObject owner,
339-
EReference reference,
340-
ReferenceEntries entries,
341-
DeserializationContext context) throws IOException {
341+
private void readReference(
342+
JsonParser jp,
343+
EObject owner,
344+
EReference reference,
345+
ReferenceEntries entries,
346+
DeserializationContext context) throws IOException {
342347

343348
if (jp.getCurrentToken() == JsonToken.START_ARRAY) {
344349
while (jp.nextToken() != JsonToken.END_ARRAY) {
@@ -349,11 +354,12 @@ private void readReference(JsonParser jp,
349354
}
350355
}
351356

352-
private void readAttribute(JsonParser jp,
353-
EObject owner,
354-
EAttribute attribute,
355-
Resource resource,
356-
DeserializationContext ctxt) throws IOException {
357+
private void readAttribute(
358+
JsonParser jp,
359+
EObject owner,
360+
EAttribute attribute,
361+
Resource resource,
362+
DeserializationContext ctxt) throws IOException {
357363

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

374-
private void readSingleAttribute(JsonParser jp,
375-
EObject owner,
376-
EAttribute attribute,
377-
Resource resource,
378-
EDataType dataType,
379-
DeserializationContext ctxt) throws IOException {
380+
private void readSingleAttribute(
381+
JsonParser jp,
382+
EObject owner,
383+
EAttribute attribute,
384+
Resource resource,
385+
EDataType dataType,
386+
DeserializationContext ctxt) throws IOException {
380387

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

src/test/java/org/emfjson/jackson/junit/TestSuite.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@
1111
*/
1212
package org.emfjson.jackson.junit;
1313

14+
import org.emfjson.jackson.junit.tests.*;
1415
import org.junit.runner.RunWith;
1516
import org.junit.runners.Suite;
1617
import org.junit.runners.Suite.SuiteClasses;
1718

18-
import org.emfjson.jackson.junit.tests.*;
19-
2019
@RunWith(Suite.class)
2120
@SuiteClasses({
2221
AnnotationTest.class,
@@ -44,4 +43,5 @@
4443
ValueTest.class,
4544
NullValueInBetweenTest.class
4645
})
47-
public class TestSuite {}
46+
public class TestSuite {
47+
}

src/test/java/org/emfjson/jackson/junit/tests/NullValueInBetweenTest.java

Lines changed: 0 additions & 44 deletions
This file was deleted.

src/test/java/org/emfjson/jackson/junit/tests/ValueTest.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import java.util.Date;
3535
import java.util.List;
3636

37+
import static org.assertj.core.api.Assertions.assertThat;
3738
import static org.junit.Assert.assertEquals;
3839
import static org.junit.Assert.assertNotNull;
3940
import static org.junit.Assert.assertTrue;
@@ -115,6 +116,43 @@ public void testStringValues() throws IOException {
115116
assertEquals(expected, mapper.valueToTree(resource));
116117
}
117118

119+
@Test
120+
public void testLoadStringValues() throws IOException {
121+
JsonNode data = mapper.createObjectNode()
122+
.put("eClass", "http://www.emfjson.org/jackson/model#//ETypes")
123+
.put("eString", "Hello")
124+
.set("eStrings", mapper.createArrayNode()
125+
.add("Hello")
126+
.add("The")
127+
.add("World"));
128+
129+
Resource resource = resourceSet.createResource(URI.createURI("tests/test.json"));
130+
resource.load(new ByteArrayInputStream(mapper.writeValueAsBytes(data)), null);
131+
132+
EObject root = resource.getContents().get(0);
133+
assertEquals(ModelPackage.Literals.ETYPES, root.eClass());
134+
135+
assertEquals("Hello", ((ETypes) root).getEString());
136+
137+
assertThat(((ETypes) root).getEStrings())
138+
.containsExactly("Hello", "The", "World");
139+
}
140+
141+
@Test
142+
public void testLoadNullValue() throws IOException {
143+
JsonNode data = mapper.createObjectNode()
144+
.put("eClass", "http://www.emfjson.org/jackson/model#//ETypes")
145+
.putNull("eString");
146+
147+
Resource resource = resourceSet.createResource(URI.createURI("tests/test.json"));
148+
resource.load(new ByteArrayInputStream(mapper.writeValueAsBytes(data)), null);
149+
150+
EObject root = resource.getContents().get(0);
151+
assertEquals(ModelPackage.Literals.ETYPES, root.eClass());
152+
153+
assertThat(((ETypes) root).getEString()).isNull();
154+
}
155+
118156
@Test
119157
public void testIntValues() throws IOException {
120158
JsonNode expected = mapper.createObjectNode()

src/test/resources/tests/test-load-null-value-in-between.json

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)