-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8d5be9e
commit fa1acbb
Showing
4 changed files
with
74 additions
and
6 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
67 changes: 67 additions & 0 deletions
67
jr-objects/src/test/java/com/fasterxml/jackson/jr/failing/ValueWriterModifier112Test.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,67 @@ | ||
package com.fasterxml.jackson.jr.failing; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator; | ||
|
||
import com.fasterxml.jackson.jr.ob.*; | ||
import com.fasterxml.jackson.jr.ob.api.*; | ||
import com.fasterxml.jackson.jr.ob.impl.JSONWriter; | ||
|
||
public class ValueWriterModifier112Test extends TestBase | ||
{ | ||
static class TestBean112 { | ||
public Path p1; | ||
public Path p2; | ||
} | ||
|
||
static class PathWriter implements ValueWriter { | ||
@Override | ||
public void writeValue(JSONWriter context, JsonGenerator g, Object value) throws IOException { | ||
g.writeString(((Path) value).toString().replace(File.separatorChar, '/')); | ||
} | ||
|
||
@Override | ||
public Class<?> valueType() { | ||
return Path.class; | ||
} | ||
} | ||
|
||
// [jackson-jr#112] | ||
public void testMultipleFieldOverrides() throws Exception | ||
{ | ||
TestBean112 input = new TestBean112(); | ||
input.p1 = Paths.get("some/path"); | ||
input.p2 = Paths.get("some/other/path"); | ||
|
||
JSON writer = JSON.builder() | ||
.register(new JacksonJrExtension() { | ||
@Override | ||
protected void register(ExtensionContext ctxt) { | ||
ctxt.insertModifier(new ReaderWriterModifier() { | ||
@Override | ||
public ValueWriter overrideStandardValueWriter(JSONWriter writeContext, Class<?> type, int stdTypeId) { | ||
if (type == Path.class) { | ||
return new PathWriter(); | ||
} | ||
return super.overrideStandardValueWriter(writeContext, type, stdTypeId); | ||
} | ||
}); | ||
ctxt.insertProvider(new ReaderWriterProvider() { | ||
@Override | ||
public ValueWriter findValueWriter(JSONWriter writeContext, Class<?> type) { | ||
if (Path.class.isAssignableFrom(type)) { | ||
return new PathWriter(); | ||
} | ||
return super.findValueWriter(writeContext, type); | ||
} | ||
}); | ||
} | ||
}).build(); | ||
String json = writer.asString(input); | ||
assertEquals(a2q("{'p1':'some/path','p2':'some/other/path'}"), json); | ||
} | ||
} |
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