mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
[mapdb] Explicitly set date format for serialization (#16657)
Between Java 17 and Java 21, serialization of Date has changed due to CLDR 42 which uses a narrow non-breaking space. To ease switching JDK versions, the serialization format is explicitly set to the Java 17 format when GsonBuilder is used. Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
This commit is contained in:
parent
1fff7eb028
commit
b6cbc7ff82
@ -35,6 +35,7 @@ import org.mapdb.DBMaker;
|
||||
import org.openhab.core.OpenHAB;
|
||||
import org.openhab.core.common.ThreadPoolManager;
|
||||
import org.openhab.core.items.Item;
|
||||
import org.openhab.core.library.types.DateTimeType;
|
||||
import org.openhab.core.persistence.FilterCriteria;
|
||||
import org.openhab.core.persistence.HistoricItem;
|
||||
import org.openhab.core.persistence.PersistenceItemInfo;
|
||||
@ -82,8 +83,8 @@ public class MapDbPersistenceService implements QueryablePersistenceService {
|
||||
private @NonNullByDefault({}) DB db;
|
||||
private @NonNullByDefault({}) Map<String, String> map;
|
||||
|
||||
private transient Gson mapper = new GsonBuilder().registerTypeHierarchyAdapter(State.class, new StateTypeAdapter())
|
||||
.create();
|
||||
private transient Gson mapper = new GsonBuilder().setDateFormat(DateTimeType.DATE_PATTERN_JSON_COMPAT)
|
||||
.registerTypeHierarchyAdapter(State.class, new StateTypeAdapter()).create();
|
||||
|
||||
@Activate
|
||||
public void activate() {
|
||||
|
@ -24,6 +24,7 @@ import java.util.stream.Stream;
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import org.openhab.core.library.types.DateTimeType;
|
||||
import org.openhab.core.library.types.DecimalType;
|
||||
import org.openhab.core.library.types.HSBType;
|
||||
import org.openhab.core.library.types.OnOffType;
|
||||
@ -45,7 +46,8 @@ import com.google.gson.GsonBuilder;
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class StateTypeAdapterTest {
|
||||
private Gson mapper = new GsonBuilder().registerTypeHierarchyAdapter(State.class, new StateTypeAdapter()).create();
|
||||
private Gson mapper = new GsonBuilder().setDateFormat(DateTimeType.DATE_PATTERN_JSON_COMPAT)
|
||||
.registerTypeHierarchyAdapter(State.class, new StateTypeAdapter()).create();
|
||||
|
||||
private static final List<DecimalType> DECIMAL_TYPE_VALUES = List.of(DecimalType.ZERO, new DecimalType(1.123),
|
||||
new DecimalType(10000000));
|
||||
|
Loading…
Reference in New Issue
Block a user