How to custom deserialize from array in Jackson?
<p>I would like to serialize / deserialize (Joda) date as an array.</p>

<p>Unfortunately, I can't figure out how to do deserializtion part:</p>

<pre><code>import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.joda.time.LocalDate;
import org.joda.time.LocalTime;

import java.io.IOException;

public class TryJodaTime {

   public static class LocalTimeSerializer extends JsonSerializer&lt;LocalTime&gt; {

      @Override
      public void serialize(LocalTime value, JsonGenerator gen, SerializerProvider serializers) throws IOException, JsonProcessingException {

         gen.writeStartArray();
         gen.writeNumber(value.getHourOfDay());
         gen.writeNumber(value.getMinuteOfHour());
         gen.writeNumber(value.getSecondOfMinute());
         gen.writeNumber(value.getMillisOfSecond());

         gen.writeEndArray();

      }
   }

   public static class LocalTimeDeserializer extends JsonDeserializer&lt;LocalTime&gt; {

      @Override
      public LocalTime deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {

         JsonToken token;

         token = jp.nextToken();
         if( token != JsonToken.START_ARRAY ) {
            throw new JsonParseException("Start array expected", jp.getCurrentLocation());
         }

         int hour = jp.nextIntValue(0);
         int minute = jp.nextIntValue(0);
         int second = jp.nextIntValue(0);
         int ms = jp.nextIntValue(0);

         token = jp.nextToken();
         if( token != JsonToken.END_ARRAY ) {
            throw new JsonParseException("End array expected", jp.getCurrentLocation());
         }

         return new LocalTime(hour, minute, second, ms);
      }
   }


   public static class MyClass {

      private LocalTime localTime;

      public MyClass() {
         localTime = LocalTime.now();
      }

      @JsonSerialize(using = LocalTimeSerializer.class)
      public LocalTime getLocalTime() {
         return localTime;
      }

      @JsonDeserialize(using = LocalTimeDeserializer.class)
      public void setLocalTime(LocalTime localTime) {
         this.localTime = localTime;
      }

   }

   public static void main(String[] args) throws IOException {


      MyClass myClass = new MyClass();
      ObjectMapper mapper = new ObjectMapper();
      String string = mapper.writeValueAsString(myClass);

      System.out.println(string);

      MyClass myClass2 = mapper.readValue(string, MyClass.class);

      System.out.println(myClass2.toString());


   }
}
</code></pre>

<p>This code causes my own exception thrown</p>

<pre><code>throw new JsonParseException("Start array expected", jp.getCurrentLocation());
</code></pre>