-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Could you please add support of java.time as is part of Java8 ? #739
Comments
Note: JodaTime and JSR310 are very different things. On Fri, Nov 20, 2015 at 1:55 PM CyborTronik [email protected]
|
minimum supported version of Java in Gson is Java 5. The next version will bump it up to Java 6. Is there a way this can be supported without bumping up the minimum supported version? |
I would guess a peer library built against Java 8 which just provides a On Sat, Nov 21, 2015 at 2:50 PM inder123 [email protected] wrote:
|
Hi I hava a question. I searched this url : https://github.com/google-gson/typeadapters |
Is this issue still relevant (after all these years)? EDIT: I guess it is until java8 is the minimum version supported Line 30 in 827e117
|
According to Oracle (https://www.oracle.com/java/technologies/java-se-support-roadmap.html), even the extended support for Java 7 ended in July 2022. |
@Mario-Eis I guess this does not matter. There are many clients of this library still using Java 7. I would guess that there are a lot or some very important internal Google projects that use Java 7. Until the gson in whole drops Java 7 support, there won't be any progress here. More info #2018 |
Until gson supports java.time properly it will not fully support java 17. We are currently migrating to java 17, and it seems that we will have to replace all gson calls, as we use java.time a lot:
|
Workaround: Create a gson instance with custom adapters like this import java.lang.reflect.Type;
import java.time.*;
import java.util.Map;
import java.util.function.Function;
import com.google.gson.*;
public class GsonWithJavaTime {
public static Gson getInstance() {
GsonBuilder builder = new GsonBuilder();
Map<Type, Function<String, Object>> parsers = Map.of(
ZonedDateTime.class, ZonedDateTime::parse,
LocalDate.class, LocalDate::parse,
LocalDateTime.class, LocalDateTime::parse
);
parsers.entrySet().forEach(entry -> builder.registerTypeAdapter(entry.getKey(), adapter(entry.getValue())));
return builder.create();
}
private static <T> JsonDeserializer<T> adapter(Function<String, T> function) {
return (element, type, context) -> function.apply(element.getAsJsonPrimitive().getAsString());
}
} |
Hi,
Could you please make builtin support of JodaTime types as is included in Java and no needs for separate library?
The text was updated successfully, but these errors were encountered: