Giter Site home page Giter Site logo

gson-javatime-serialisers's People

Contributors

dependabot[bot] avatar gkopff avatar mwanji avatar steven509 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

gson-javatime-serialisers's Issues

Serialisation of Durations

It doesn't seem as if this adds a converter for java.time.Duration:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.google.gson.internal.reflect.ReflectionHelper 
    (file:/Users/ifly6/.m2/repository/com/google/code/gson/gson/2.9.1/gson-2.9.1.jar) to field
    java.time.Duration.seconds
WARNING: Please consider reporting this to the maintainers of com.google.gson.internal.reflect.ReflectionHelper
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

Is that intentional?

Does InstantConverter support UTC offset values?

Can I deserialize a value using InstantConverter that includes a UTC offset like, "2017-04-22T00:00:00-04:00", or does the string have to be in UTC? I think the answer is that it doesn't support UTC offset, because I tried and it didn't work, but that could be user error.
Thanks!

Tests are too weak

I can change Converters#registerAll(GsonBuilder) to the following, and all tests still pass:

public static GsonBuilder registerAll(GsonBuilder builder)
  {
    if (builder == null) { throw new NullPointerException("builder cannot be null"); }

//    registerLocalDate(builder);
//    registerLocalDateTime(builder);
//    registerLocalTime(builder);
//    registerOffsetDateTime(builder);
//    registerOffsetTime(builder);
    registerZonedDateTime(builder);

    return builder;
  }

ConvertersTest should probably convert Container to a JsonTree and compare values against what is returned using the converters directly. In my example, LocalDate becomes {"year":2014,"month":12,"day":11}, which is deserialised without a problem.

UPDATE:

Just saw that this is the case for ALL tests. I can comment out the type adapter registration and the test still passes. So essentially nothing is being tested.

DateTimeParseException for unknown reason

java.time.format.DateTimeParseException: Text '' could not be parsed at index 0
at java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1947)
at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1849)
at com.fatboyindustrial.gsonjavatime.LocalTimeConverter.deserialize(LocalTimeConverter.java:95)
at com.fatboyindustrial.gsonjavatime.LocalTimeConverter.deserialize(LocalTimeConverter.java:1)
at com.google.gson.TreeTypeAdapter.read(TreeTypeAdapter.java:58)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:103)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:196)
at com.google.gson.Gson.fromJson(Gson.java:810)
at com.google.gson.Gson.fromJson(Gson.java:775)
at com.google.gson.Gson.fromJson(Gson.java:724)
at com.google.gson.Gson.fromJson(Gson.java:696)
at xxx.util.JsonUtil.fromJson(JsonUtil.java:19)
at xxx.servlet.yyy.zzzServlet.doGet(CreateSchedule.java:38)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.logging.log4j.web.Log4jServletFilter.doFilter(Log4jServletFilter.java:71)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:617)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:668)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1521)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1478)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)

I am continuously getting the above the error. but i am failed to find the exact cause. i have downloaded the source and attached it to my application. when i debug it, i found the exception is being thrown when LocalTime is formated from empty string

Add a converter to ZoneId

Adding a serializer/de-serializer for java.time.ZoneId

Don't we need serializer/De-serializer for ZoneId's?

Instant converter working; LocalDate(Time) not

The Instant converter is working great for me, but I'm having trouble with the LocalDate and LocalDateTime converters.

private Instant date;
private LocalDateTime date2;
private LocalDate date3;
private Instant date4;

private static Gson gson = Converters.registerAll(new GsonBuilder()).create();

public MyClass(final Instant date) {
    this.date = date;
    this.date2 = LocalDateTime.ofInstant(date, ZoneId.of("UTC"));
    this.date3 = date2.toLocalDate();
    this.date4 = date3.atStartOfDay().toInstant(ZoneOffset.UTC);
}

public String toJSON() {
    return gson.toJson(this);
}

When I call toJSON, the two Instants (date, date4) are serialized properly to ISO timestamps, but date2 and date3 serialize to {"date": {"year", "month", "day"}, "time": {...}} and {"year", "month", "day"} respectively.

Given the relatively simplicity of the implementation of this package, I'm not sure where the error might lie, but I just wanted to inquire here in case you have any ideas.

Serializer from Threeten backport

Helllo,
I have Forked your serializers to be used in Java 7 with threeten library, a backport of java8 date time to Java7. It uses another artifactId to not interfere with the Java8 version.
Do you want to publish it to maven? Maybe i could do a pull request by creating a new branch for this variation?

Thank you for your attention
Phil.

InstantTypeAdaptor fails on seconds

Hi ,

If json has time field represented as number of Seconds InstantConverter failed to deserialize it.

I have a test case where i use gson parse along with awaitility with seconds
Published kafka record has gson.tojson mapping
20230728_125833

Throwing following exception::

Failed making field "java.time.Instant.seconds' accessible; either change its visibility or write a custom TypeAdapter for its declaring typel
þal.reflect .ReflectionHelper.makeAccessible (ReflectionHelper.java:22)
mal.bind. ReflectiveTypeAdapterFactory.getBoundField
Caused by: java.lang.reflect.Inaccessible@bjectException: Unable to make field private final long java.time.Instant.seconds accessible: module

I tried following way of registering adaptor but still no success

Any suggestions could you kindly provide.. thanks in advance

Screenshot_20230728_113453_Gallery

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.