-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
50 changed files
with
2,539 additions
and
796 deletions.
There are no files selected for viewing
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
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
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
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
104 changes: 104 additions & 0 deletions
104
...ntation-foundation/src/main/java/io/arex/foundation/serializer/GsonRequestSerializer.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package io.arex.foundation.serializer; | ||
|
||
import com.google.auto.service.AutoService; | ||
import com.google.gson.Gson; | ||
import com.google.gson.GsonBuilder; | ||
import io.arex.foundation.serializer.custom.ProtobufAdapterFactory; | ||
import io.arex.foundation.serializer.custom.SerializerExclusionStrategy; | ||
import io.arex.foundation.serializer.custom.StringAdapter; | ||
import io.arex.foundation.serializer.custom.time.adapter.CalendarAdapter; | ||
import io.arex.foundation.serializer.custom.time.adapter.ClassAdapter; | ||
import io.arex.foundation.serializer.custom.time.adapter.DateAdapter; | ||
import io.arex.foundation.serializer.custom.time.adapter.DateTimeAdapter; | ||
import io.arex.foundation.serializer.custom.time.adapter.InstantAdapter; | ||
import io.arex.foundation.serializer.custom.time.adapter.JodaLocalDateAdapter; | ||
import io.arex.foundation.serializer.custom.time.adapter.JodaLocalDateTimeAdapter; | ||
import io.arex.foundation.serializer.custom.time.adapter.JodaLocalTimeAdapter; | ||
import io.arex.foundation.serializer.custom.time.adapter.LocalDateAdapter; | ||
import io.arex.foundation.serializer.custom.time.adapter.LocalDateTimeAdapter; | ||
import io.arex.foundation.serializer.custom.time.adapter.LocalTimeAdapter; | ||
import io.arex.foundation.serializer.custom.time.adapter.OffsetDateTimeAdapter; | ||
import io.arex.foundation.serializer.custom.time.adapter.TimeZoneAdapter; | ||
import io.arex.foundation.serializer.custom.time.adapter.XMLGregorianCalendarAdapter; | ||
import io.arex.inst.runtime.serializer.StringSerializable; | ||
import org.joda.time.DateTime; | ||
|
||
import javax.xml.datatype.XMLGregorianCalendar; | ||
import java.lang.reflect.Type; | ||
import java.sql.Time; | ||
import java.sql.Timestamp; | ||
import java.time.Instant; | ||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import java.time.LocalTime; | ||
import java.time.OffsetDateTime; | ||
import java.util.Calendar; | ||
import java.util.Date; | ||
import java.util.GregorianCalendar; | ||
import java.util.TimeZone; | ||
|
||
@AutoService(StringSerializable.class) | ||
public class GsonRequestSerializer implements StringSerializable{ | ||
|
||
public static GsonRequestSerializer INSTANCE = new GsonRequestSerializer(); | ||
private final Gson serializer; | ||
|
||
public GsonRequestSerializer() { | ||
this.serializer = new GsonBuilder() | ||
.registerTypeAdapter(DateTime.class, new DateTimeAdapter.GsonSerializer(true)) | ||
.registerTypeAdapter(org.joda.time.LocalDateTime.class, new JodaLocalDateTimeAdapter.GsonSerializer(true)) | ||
.registerTypeAdapter(org.joda.time.LocalDate.class, new JodaLocalDateAdapter.GsonSerializer()) | ||
.registerTypeAdapter(org.joda.time.LocalTime.class, new JodaLocalTimeAdapter.GsonSerializer(true)) | ||
.registerTypeAdapter(LocalDateTime.class, new LocalDateTimeAdapter.GsonSerializer(true)) | ||
.registerTypeAdapter(LocalDate.class, new LocalDateAdapter.GsonSerializer()) | ||
.registerTypeAdapter(LocalTime.class, new LocalTimeAdapter.GsonSerializer(true)) | ||
.registerTypeAdapter(Calendar.class, new CalendarAdapter.GsonSerializer(true)) | ||
.registerTypeAdapter(GregorianCalendar.class, new CalendarAdapter.GsonSerializer(true)) | ||
.registerTypeAdapter(XMLGregorianCalendar.class, new XMLGregorianCalendarAdapter.GsonSerializer(true)) | ||
.registerTypeAdapter(Timestamp.class, new DateAdapter.GsonSerializer(true)) | ||
.registerTypeAdapter(Date.class, new DateAdapter.GsonSerializer(true)) | ||
.registerTypeAdapter(java.sql.Date.class, new DateAdapter.GsonSerializer(true)) | ||
.registerTypeAdapter(Time.class, new DateAdapter.GsonSerializer(true)) | ||
.registerTypeAdapter(Instant.class, new InstantAdapter.GsonSerializer(true)) | ||
.registerTypeAdapter(Class.class, new ClassAdapter.GsonSerializer()) | ||
.registerTypeAdapter(OffsetDateTime.class, new OffsetDateTimeAdapter.GsonSerializer(true)) | ||
.registerTypeAdapter(TimeZone.class, new TimeZoneAdapter.GsonSerializer()) | ||
.registerTypeAdapter(String.class, new StringAdapter.GsonSerializer()) | ||
.registerTypeAdapterFactory(new ProtobufAdapterFactory()) | ||
.enableComplexMapKeySerialization() | ||
.setExclusionStrategies(new SerializerExclusionStrategy.GsonExclusion()) | ||
.disableHtmlEscaping() | ||
.create(); | ||
} | ||
|
||
@Override | ||
public String name() { | ||
return "gson-request"; | ||
} | ||
|
||
@Override | ||
public String serialize(Object object) throws Throwable { | ||
if (object == null) { | ||
return null; | ||
} | ||
return serializer.toJson(object); | ||
} | ||
|
||
@Override | ||
public <T> T deserialize(String value, Class<T> clazz) throws Throwable { | ||
// request serializer not need deserialize | ||
return null; | ||
} | ||
|
||
@Override | ||
public <T> T deserialize(String value, Type type) throws Throwable { | ||
// request serializer not need deserialize | ||
return null; | ||
} | ||
|
||
@Override | ||
public StringSerializable reCreateSerializer() { | ||
INSTANCE = new GsonRequestSerializer(); | ||
return INSTANCE; | ||
} | ||
} |
Oops, something went wrong.