use of com.google.api.server.spi.types.SimpleDate in project endpoints-java by cloudendpoints.
the class ServletResponseResultWriterTest method testTypeChangesInMapAsString.
@Test
public void testTypeChangesInMapAsString() throws Exception {
Map<String, Object> value = new HashMap<>();
value.put("nonPrimitive", 100L);
value.put("primitive", 200L);
value.put("date", new Date(DATE_VALUE));
value.put("dateAndTime", DateAndTime.parseRfc3339String(DATE_AND_TIME_VALUE_STRING));
value.put("simpleDate", new SimpleDate(2002, 10, 2));
testTypeChangesAsString(value);
}
use of com.google.api.server.spi.types.SimpleDate in project endpoints-java by cloudendpoints.
the class ServletResponseResultWriter method getWriteSimpleDateAsStringModule.
private static SimpleModule getWriteSimpleDateAsStringModule() {
JsonSerializer<SimpleDate> simpleDateSerializer = new JsonSerializer<SimpleDate>() {
@Override
public void serialize(SimpleDate value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
jgen.writeString(String.format("%04d-%02d-%02d", value.getYear(), value.getMonth(), value.getDay()));
}
};
SimpleModule writeSimpleDateAsModule = new SimpleModule("writeSimpleDateAsModule", new Version(1, 0, 0, null, null, null));
writeSimpleDateAsModule.addSerializer(SimpleDate.class, simpleDateSerializer);
return writeSimpleDateAsModule;
}
use of com.google.api.server.spi.types.SimpleDate in project endpoints-java by cloudendpoints.
the class ServletResponseResultWriterTest method testTypeChangesInBeanAsString.
@SuppressWarnings("unused")
public void testTypeChangesInBeanAsString() throws Exception {
Object value = new Object() {
public long getPrimitive() {
return 200L;
}
public Long getNonPrimitive() {
return 100L;
}
public Long getLongNull() {
return null;
}
public String getStringNull() {
return null;
}
public String getStringEmpty() {
return "";
}
public Date getDate() {
return new Date(DATE_VALUE);
}
public Date getDateNull() {
return null;
}
public DateAndTime getDateAndTime() {
return DateAndTime.parseRfc3339String(DATE_AND_TIME_VALUE_STRING);
}
public DateAndTime getDateAndTimeNull() {
return null;
}
public SimpleDate getSimpleDate() {
return new SimpleDate(2002, 10, 2);
}
public SimpleDate getSimpleDateNull() {
return null;
}
public Long[] getEmptyLongArray() {
return new Long[0];
}
public List<Long> getEmptyLongList() {
return new ArrayList<>();
}
};
ObjectNode output = testTypeChangesAsString(value);
assertTrue(output.path("longNull").isMissingNode());
assertTrue(output.path("stringNull").isMissingNode());
assertEquals("", output.path("stringEmpty").asText());
assertTrue(output.path("dateNull").isMissingNode());
assertTrue(output.path("dateAndTimeNull").isMissingNode());
assertTrue(output.path("simpleDateNull").isMissingNode());
assertTrue(output.path("emptyLongArray").isMissingNode());
assertTrue(output.path("emptyLongList").isMissingNode());
}
use of com.google.api.server.spi.types.SimpleDate in project endpoints-java by cloudendpoints.
the class ServletRequestParamReaderTest method testReadSimpleDate_success.
@Test
public void testReadSimpleDate_success() throws Exception {
Method method = TestEndpoint.class.getDeclaredMethod("getSimpleDate", SimpleDate.class);
Object[] params = null;
params = readParameters("{" + TestEndpoint.NAME_DATE_AND_TIME + ":\"2002-10-02\"}", method);
assertThat(Arrays.asList(params)).containsExactly(new SimpleDate(2002, 10, 2)).inOrder();
}
Aggregations