Skip to content

Commit

Permalink
Fixes #11 - Use Jackson's com.fasterxml.jackson.databind.util.RawValu…
Browse files Browse the repository at this point in the history
…e when needing to serialize as raw

X-Refs:
- FasterXML/jackson-databind#737
- FasterXML/jackson-databind#743
  • Loading branch information
martin-g committed May 10, 2015
1 parent f33573a commit ac61f56
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
10 changes: 9 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<mvn.build.java.version>${java.version}</mvn.build.java.version>
<mvn.version>3.0.0</mvn.version>

<com.fasterxml.jackson.version>2.3.0</com.fasterxml.jackson.version>
<com.fasterxml.jackson.version>2.6.0-SNAPSHOT</com.fasterxml.jackson.version>
<junit.version>4.12</junit.version>
<hamcrest.version>1.3</hamcrest.version>
<maven-bundle-plugin.version>2.5.2</maven-bundle-plugin.version>
Expand Down Expand Up @@ -166,4 +166,12 @@
</plugins>
</build>

<repositories>
<repository>
<id>Sonatype OSS snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
<releases><enabled>false</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.util.RawValue;
import de.agilecoders.wicket.jquery.util.Json;

import java.io.IOException;
Expand All @@ -15,6 +16,22 @@
public class RawSerializer extends JsonSerializer<Json.RawValue> {
@Override
public void serialize(Json.RawValue value, JsonGenerator jsonGenerator, SerializerProvider provider) throws IOException {
jsonGenerator.writeObject(value.value());
jsonGenerator.writeObject(new RV(value.value()));
}

/**
* An extension of com.fasterxml.jackson.databind.util.RawValue that delegates
* toString() to the rawValue
*/
private static class RV extends RawValue {

public RV(String v) {
super(v);
}

@Override
public String toString() {
return rawValue().toString();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
import org.junit.Test;

import static de.agilecoders.wicket.jquery.JQuery.$;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.endsWith;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.startsWith;

/**
* Tests for serializing AbstractConfig to JSON
Expand Down

0 comments on commit ac61f56

Please sign in to comment.