Last active
April 26, 2017 21:47
-
-
Save l-gu/6f8c87c2bde3659d513fbe0a75227c37 to your computer and use it in GitHub Desktop.
Java util.Date literal values
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
/* | |
* Created on 2017-04-26 ( Date ISO 2017-04-26 - Time 21:50:59 ) | |
* Generated by Telosys ( http://www.telosys.org/ ) version 3.0.0 | |
*/ | |
package org.demo.persistence.impl.redis.commons.json; | |
import static org.junit.Assert.assertEquals; | |
import static org.junit.Assert.assertNotNull; | |
import java.text.SimpleDateFormat; | |
import org.demo.data.record.FooDateRecord; | |
import org.junit.Test; | |
/** | |
* JUnit tests | |
* | |
* @author Telosys | |
* | |
*/ | |
public class FooDateJsonMappingTest { | |
@Test | |
public void testPersistenceService() throws Exception { | |
JsonMapper mapper = JsonMapperProvider.getJsonMapper(); | |
FooDateRecord object1 = buildInstance() ; | |
System.out.println("instance 1 : " + object1); | |
String json = mapper.beanToJson(object1); | |
FooDateRecord object2 = mapper.jsonToBean(json, FooDateRecord.class); | |
System.out.println("instance 2 : " + object2); | |
//--- Check all attributes | |
assertNotNull(object2); | |
assertEquals(object1.getId(), object2.getId() ); | |
assertEquals(object1.getD(), object2.getD() ); | |
assertEquals(object1.getT(), object2.getT() ); | |
assertEquals(object1.getTs(), object2.getTs() ); | |
} | |
private FooDateRecord buildInstance() throws Exception { | |
FooDateRecord o = new FooDateRecord(); | |
//--- Key values | |
o.setId(1); // "id" | |
//--- Other values | |
o.setD((new SimpleDateFormat("yyyy-MM-dd")).parse("2001-06-22")); // "date" : java.util.Date | |
o.setT((new SimpleDateFormat("HH:mm:ss")).parse("12:34:56")); // "time" : java.util.Date | |
o.setT((new SimpleDateFormat("HH:mm:ss.SSS")).parse("12:34:56.789")); // "time" : java.util.Date | |
o.setTs((new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS")).parse("2001-06-22 12:34:56.789")); // "timestamp" : java.util.Date | |
return o ; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment