-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent an NPE caused by AbstractTypeMapper returning "null", that is abstaining from the type decision. This is useful e.g. to have an optional type discriminator present which is generated by the system but not needed on reparsing if parse is called with the correct type known by other means. Add test.
- Loading branch information
Showing
2 changed files
with
36 additions
and
1 deletion.
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
34 changes: 34 additions & 0 deletions
34
src/test/java/org/svenson/TypeMapperNeutralityTestCase.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,34 @@ | ||
package org.svenson; | ||
|
||
import org.junit.Test; | ||
import org.svenson.matcher.PrefixPathMatcher; | ||
import org.svenson.matcher.TruePathMatcher; | ||
|
||
/** | ||
* Created by sven on 07.10.15. | ||
*/ | ||
public class TypeMapperNeutralityTestCase | ||
{ | ||
|
||
@Test | ||
public void testName() throws Exception | ||
{ | ||
JSONParser parser = new JSONParser(); | ||
Mapper typeMapper = new Mapper(); | ||
typeMapper.setPathMatcher(new TruePathMatcher()); | ||
|
||
parser.setTypeMapper(typeMapper); | ||
|
||
parser.parse("{\"foo\":1}"); | ||
|
||
} | ||
|
||
private static class Mapper extends AbstractPropertyValueBasedTypeMapper | ||
{ | ||
@Override | ||
protected Class getTypeHintFromTypeProperty(Object value) throws IllegalStateException | ||
{ | ||
return null; | ||
} | ||
} | ||
} |