-
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.
BugFix: TeenyJson now can parse formatted jsons, TeenyApplicationTest…
…s now uses TeenyJson instead of Gson
- Loading branch information
Showing
5 changed files
with
119 additions
and
9 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
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
35 changes: 35 additions & 0 deletions
35
src/test/java/net/jonathangiles/tools/teenyhttpd/TeenyJsonConverter.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,35 @@ | ||
package net.jonathangiles.tools.teenyhttpd; | ||
|
||
import net.jonathangiles.tools.teenyhttpd.json.TeenyJson; | ||
import net.jonathangiles.tools.teenyhttpd.model.MessageConverter; | ||
|
||
import java.io.BufferedOutputStream; | ||
import java.io.IOException; | ||
import java.lang.reflect.Type; | ||
|
||
public class TeenyJsonConverter implements MessageConverter { | ||
|
||
final TeenyJson teenyJson = new TeenyJson(); | ||
|
||
@Override | ||
public String getContentType() { | ||
return "application/json"; | ||
} | ||
|
||
@Override | ||
public void write(Object value, BufferedOutputStream dataOut) throws IOException { | ||
|
||
|
||
if (value instanceof String) { | ||
dataOut.write(((String) value).getBytes()); | ||
return; | ||
} | ||
|
||
dataOut.write(teenyJson.writeValueAsString(value).getBytes()); | ||
} | ||
|
||
@Override | ||
public Object read(String value, Type type) { | ||
return teenyJson.readValue(value, type); | ||
} | ||
} |
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