diff options
author | Anton Tananaev <anton@traccar.org> | 2022-09-21 21:47:45 -0700 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2022-09-21 21:47:45 -0700 |
commit | abb26e80a5617424d960a0f7d0b98fcb379a5224 (patch) | |
tree | a21f23375279d9ae84a18dc7d6a2991feca2ef64 /src/main/java | |
parent | 13b065fc4e8e1a4dc1f35312869151418fc660bd (diff) | |
download | trackermap-server-abb26e80a5617424d960a0f7d0b98fcb379a5224.tar.gz trackermap-server-abb26e80a5617424d960a0f7d0b98fcb379a5224.tar.bz2 trackermap-server-abb26e80a5617424d960a0f7d0b98fcb379a5224.zip |
Fix forwarding date format
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/org/traccar/MainModule.java | 9 | ||||
-rw-r--r-- | src/main/java/org/traccar/helper/ObjectMapperContextResolver.java | 38 |
2 files changed, 42 insertions, 5 deletions
diff --git a/src/main/java/org/traccar/MainModule.java b/src/main/java/org/traccar/MainModule.java index e0617a734..94669915b 100644 --- a/src/main/java/org/traccar/MainModule.java +++ b/src/main/java/org/traccar/MainModule.java @@ -62,6 +62,7 @@ import org.traccar.geolocation.UnwiredGeolocationProvider; import org.traccar.handler.GeocoderHandler; import org.traccar.handler.GeolocationHandler; import org.traccar.handler.SpeedLimitHandler; +import org.traccar.helper.ObjectMapperContextResolver; import org.traccar.helper.SanitizerModule; import org.traccar.mail.LogMailManager; import org.traccar.mail.MailManager; @@ -81,7 +82,6 @@ import javax.annotation.Nullable; import javax.inject.Singleton; import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.ext.ContextResolver; import java.io.IOException; import java.net.InetAddress; import java.net.UnknownHostException; @@ -110,14 +110,13 @@ public class MainModule extends AbstractModule { objectMapper.registerModule(new SanitizerModule()); } objectMapper.registerModule(new JSR353Module()); - objectMapper.setConfig(objectMapper - .getSerializationConfig().without(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)); + objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); return objectMapper; } @Provides - public static Client provideClient(ObjectMapper objectMapper) { - return ClientBuilder.newClient().register((ContextResolver<ObjectMapper>) clazz -> objectMapper); + public static Client provideClient(ObjectMapperContextResolver objectMapperContextResolver) { + return ClientBuilder.newClient().register(objectMapperContextResolver); } @Singleton diff --git a/src/main/java/org/traccar/helper/ObjectMapperContextResolver.java b/src/main/java/org/traccar/helper/ObjectMapperContextResolver.java new file mode 100644 index 000000000..b40e30d76 --- /dev/null +++ b/src/main/java/org/traccar/helper/ObjectMapperContextResolver.java @@ -0,0 +1,38 @@ +/* + * Copyright 2022 Anton Tananaev (anton@traccar.org) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.traccar.helper; + +import com.fasterxml.jackson.databind.ObjectMapper; + +import javax.inject.Inject; +import javax.ws.rs.ext.ContextResolver; + +// This does not work as a lambda +public class ObjectMapperContextResolver implements ContextResolver<ObjectMapper> { + + private final ObjectMapper objectMapper; + + @Inject + public ObjectMapperContextResolver(ObjectMapper objectMapper) { + this.objectMapper = objectMapper; + } + + @Override + public ObjectMapper getContext(Class<?> clazz) { + return objectMapper; + } + +} |