Fix serialization of local dates
This commit is contained in:
parent
9c788769af
commit
75b642f9bf
@ -6,10 +6,16 @@ import java.time.LocalDateTime;
|
||||
import org.apache.commons.beanutils.PropertyUtils;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
public abstract class AbstractMetadata implements IMetadata {
|
||||
@JsonIgnore
|
||||
private MetadataFormat formatName = MetadataFormat.UNKNOWN;
|
||||
|
||||
@JsonIgnore
|
||||
protected LocalDateTime written = null;
|
||||
@JsonProperty("modified")
|
||||
protected LocalDateTime _modified;
|
||||
|
||||
public MetadataFormat getFormatName() {
|
||||
|
@ -59,8 +59,6 @@ import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.json.JSONTokener;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
|
||||
import com.fasterxml.jackson.annotation.PropertyAccessor;
|
||||
import com.fasterxml.jackson.core.JsonFactory;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
@ -80,11 +78,10 @@ public class ParsingUtilities {
|
||||
SimpleModule module = new SimpleModule();
|
||||
module.addSerializer(Double.class, new SerializationFilters.DoubleSerializer());
|
||||
module.addSerializer(double.class, new SerializationFilters.DoubleSerializer());
|
||||
module.addSerializer(OffsetDateTime.class, new SerializationFilters.DateSerializer());
|
||||
|
||||
module.addSerializer(OffsetDateTime.class, new SerializationFilters.OffsetDateSerializer());
|
||||
module.addSerializer(LocalDateTime.class, new SerializationFilters.LocalDateSerializer());
|
||||
|
||||
mapper.registerModule(module);
|
||||
// mapper.setVisibility(PropertyAccessor.ALL, Visibility.NONE);
|
||||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.google.refine.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.OffsetDateTime;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
@ -90,10 +91,10 @@ public class SerializationFilters {
|
||||
/**
|
||||
* Serialize dates by ISO format.
|
||||
*/
|
||||
public static class DateSerializer extends StdSerializer<OffsetDateTime> {
|
||||
public static class OffsetDateSerializer extends StdSerializer<OffsetDateTime> {
|
||||
private static final long serialVersionUID = 93872874L;
|
||||
|
||||
public DateSerializer() {
|
||||
public OffsetDateSerializer() {
|
||||
super(OffsetDateTime.class);
|
||||
}
|
||||
|
||||
@ -103,4 +104,21 @@ public class SerializationFilters {
|
||||
gen.writeString(ParsingUtilities.dateToString(arg0));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize dates by ISO format.
|
||||
*/
|
||||
public static class LocalDateSerializer extends StdSerializer<LocalDateTime> {
|
||||
private static final long serialVersionUID = 93872874L;
|
||||
|
||||
public LocalDateSerializer() {
|
||||
super(LocalDateTime.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(LocalDateTime arg0, JsonGenerator gen, SerializerProvider s)
|
||||
throws IOException {
|
||||
gen.writeString(ParsingUtilities.localDateToString(arg0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user