0

I have Match class and field Date start. My goal is get start as timestamp. I use Spring, AngularJs, and jackson as json converter.

Spring Controller:

 @RequestMapping(value = "/web2/getMatch", method =RequestMethod.POST) public @ResponseBody Match getPicksHistory() { PickDAO pd = new PickDAO(); return pd.getMatch(); } 

On AgularJS controler:

var res = $http.post(urlSer.url+"web2/getMatch"); res.success(function(data, status, headers, config) { // now returns data.start = "Aug 8, 2015 7:00:00 PM" // My goal is get as timestamp }); 
1
  • "Aug 8, 2015 7:00:00 PM" is a timestamp. If you want to format it differently you'll need to show the definition Match class and type of its start field. Commented Aug 25, 2015 at 8:43

2 Answers 2

1

I assume that by 'timestamp' you mean a numeric timestamp as opposed to a textual representation. You can use a custom ObjectMapper:

@Component @Primary public class CustomObjectMapper extends ObjectMapper { public CustomObjectMapper() { configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, true); } } 
Sign up to request clarification or add additional context in comments.

Comments

0

I use jackson-databind:2.6.1 and JsonSerializer

@Component public class JsonDateSerializer extends JsonSerializer<Date>{ @Override public void serialize(Date date, JsonGenerator gen, SerializerProvider serializers) throws IOException, JsonProcessingException { gen.writeNumber(date.getTime()); } } 

2 Comments

Is there any advantage over the solution I posted?
No I found it before your answer :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.