Skip to content

Commit ac61f56

Browse files
committed
Fixes #11 - Use Jackson's com.fasterxml.jackson.databind.util.RawValue when needing to serialize as raw
X-Refs: - FasterXML/jackson-databind#737 - FasterXML/jackson-databind#743
1 parent f33573a commit ac61f56

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

pom.xml

+9-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<mvn.build.java.version>${java.version}</mvn.build.java.version>
2121
<mvn.version>3.0.0</mvn.version>
2222

23-
<com.fasterxml.jackson.version>2.3.0</com.fasterxml.jackson.version>
23+
<com.fasterxml.jackson.version>2.6.0-SNAPSHOT</com.fasterxml.jackson.version>
2424
<junit.version>4.12</junit.version>
2525
<hamcrest.version>1.3</hamcrest.version>
2626
<maven-bundle-plugin.version>2.5.2</maven-bundle-plugin.version>
@@ -166,4 +166,12 @@
166166
</plugins>
167167
</build>
168168

169+
<repositories>
170+
<repository>
171+
<id>Sonatype OSS snapshots</id>
172+
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
173+
<releases><enabled>false</enabled></releases>
174+
<snapshots><enabled>true</enabled></snapshots>
175+
</repository>
176+
</repositories>
169177
</project>

src/main/java/de/agilecoders/wicket/jquery/util/serializer/RawSerializer.java

+18-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.fasterxml.jackson.core.JsonGenerator;
44
import com.fasterxml.jackson.databind.JsonSerializer;
55
import com.fasterxml.jackson.databind.SerializerProvider;
6+
import com.fasterxml.jackson.databind.util.RawValue;
67
import de.agilecoders.wicket.jquery.util.Json;
78

89
import java.io.IOException;
@@ -15,6 +16,22 @@
1516
public class RawSerializer extends JsonSerializer<Json.RawValue> {
1617
@Override
1718
public void serialize(Json.RawValue value, JsonGenerator jsonGenerator, SerializerProvider provider) throws IOException {
18-
jsonGenerator.writeObject(value.value());
19+
jsonGenerator.writeObject(new RV(value.value()));
20+
}
21+
22+
/**
23+
* An extension of com.fasterxml.jackson.databind.util.RawValue that delegates
24+
* toString() to the rawValue
25+
*/
26+
private static class RV extends RawValue {
27+
28+
public RV(String v) {
29+
super(v);
30+
}
31+
32+
@Override
33+
public String toString() {
34+
return rawValue().toString();
35+
}
1936
}
2037
}

src/test/java/de/agilecoders/wicket/jquery/AbstractConfigTest.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
import org.junit.Test;
77

88
import static de.agilecoders.wicket.jquery.JQuery.$;
9-
import static org.hamcrest.CoreMatchers.*;
9+
import static org.hamcrest.CoreMatchers.containsString;
10+
import static org.hamcrest.CoreMatchers.endsWith;
11+
import static org.hamcrest.CoreMatchers.is;
12+
import static org.hamcrest.CoreMatchers.startsWith;
1013

1114
/**
1215
* Tests for serializing AbstractConfig to JSON

0 commit comments

Comments
 (0)