use of com.squareup.moshi.adapters.Rfc3339DateJsonAdapter in project axis-axis2-java-core by apache.
the class MoshiXMLStreamWriterTest method testMoshiXMLStreamWriter.
@Test
public void testMoshiXMLStreamWriter() throws Exception {
jsonString = "{\"response\":{\"return\":{\"name\":\"kate\",\"age\":\"35\",\"gender\":\"female\"}}}";
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Moshi moshi = new Moshi.Builder().add(Date.class, new Rfc3339DateJsonAdapter()).build();
JsonAdapter<Object> adapter = moshi.adapter(Object.class);
BufferedSink sink = Okio.buffer(Okio.sink(baos));
JsonWriter jsonWriter = JsonWriter.of(sink);
String fileName = "test-resources/custom_schema/testSchema_1.xsd";
InputStream is = new FileInputStream(fileName);
XmlSchemaCollection schemaCol = new XmlSchemaCollection();
XmlSchema schema = schemaCol.read(new StreamSource(is));
List<XmlSchema> schemaList = new ArrayList<XmlSchema>();
schemaList.add(schema);
QName elementQName = new QName("http://www.w3schools.com", "response");
ConfigurationContext configCtxt = new ConfigurationContext(new AxisConfiguration());
MoshiXMLStreamWriter moshiXMLStreamWriter = new MoshiXMLStreamWriter(jsonWriter, elementQName, schemaList, configCtxt);
OMElement omElement = getResponseOMElement();
moshiXMLStreamWriter.writeStartDocument();
omElement.serialize(moshiXMLStreamWriter);
moshiXMLStreamWriter.writeEndDocument();
String actualString = baos.toString();
sink.close();
Assert.assertEquals(jsonString, actualString);
}
use of com.squareup.moshi.adapters.Rfc3339DateJsonAdapter in project moshi by square.
the class IncludeNullsForOneType method run.
public void run() throws Exception {
Moshi moshi = new Moshi.Builder().add(Date.class, new Rfc3339DateJsonAdapter()).add(new TournamentWithNullsAdapter()).build();
JsonAdapter<Tournament> tournamentAdapter = moshi.adapter(Tournament.class);
// Moshi normally skips nulls, but with our adapter registered they are emitted.
Tournament withNulls = new Tournament("Waterloo Classic", null, null);
System.out.println(tournamentAdapter.toJson(withNulls));
}
Aggregations