Android Open Source - AndroidAquarium Aquarium Readings Jackson






From Project

Back to project page AndroidAquarium.

License

The source code is released under:

MIT License

If you think the Android project AndroidAquarium listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.kypeli.aquarium.models;
/*from  www . ja  v  a 2s  . co  m*/
import org.codehaus.jackson.JsonParser;
import org.codehaus.jackson.JsonProcessingException;
import org.codehaus.jackson.annotate.JsonProperty;
import org.codehaus.jackson.map.DeserializationContext;
import org.codehaus.jackson.map.JsonDeserializer;
import org.codehaus.jackson.map.annotate.JsonDeserialize;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

public class AquariumReadingsJackson {
    @JsonProperty("measurements")
    public ArrayList<Reading> readings;

    public static class Reading {
        @JsonProperty("epoch_timestamp")
        public long epoch;
        public Float temperature;
        @JsonDeserialize(using = TemperatureJsonDateSerializer.class)
        public Date timestamp;
    }

    public static class TemperatureJsonDateSerializer extends JsonDeserializer<Date> {
        @Override
        public Date deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
            SimpleDateFormat formatter = new SimpleDateFormat("EEE, dd MMM yyyy H:m:s ZZZ");
            Date d = null;
            try {
                d = formatter.parse(jp.getText());
            } catch (ParseException e) {
                e.printStackTrace();
            }

            return d;
        }
    }
 }




Java Source Code List

com.kypeli.aquarium.AquariumValueReader.java
com.kypeli.aquarium.MainActivity.java
com.kypeli.aquarium.TemperatureFragment.java
com.kypeli.aquarium.models.AquariumReadingsJackson.java
com.kypeli.aquarium.models.AquariumReadings.java
com.kypeli.aquarium.volley.GsonRequest.java
com.kypeli.aquarium.volley.JacksonRequest.java