diff --git a/common/pom.xml b/common/pom.xml index a27b3e3..92f46cf 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -55,7 +55,7 @@ com.tngtech.archunit - archunit-junit5-api + archunit-junit5 test @@ -126,7 +126,11 @@ jakarta.el:jakarta.el-api org.glassfish:jakarta.el org.hibernate.validator:hibernate-validator + com.tngtech.archunit:archunit-junit5 + + com.tngtech.archunit:archunit-junit5-api + diff --git a/core/pom.xml b/core/pom.xml index b4548d6..32ee412 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -75,7 +75,7 @@ com.tngtech.archunit - archunit-junit5-api + archunit-junit5 test @@ -158,7 +158,11 @@ jakarta.el:jakarta.el-api org.glassfish:jakarta.el org.hibernate.validator:hibernate-validator + com.tngtech.archunit:archunit-junit5 + + com.tngtech.archunit:archunit-junit5-api + diff --git a/core/src/test/java/org/fuin/objects4j/core/ArchitectureTest.java b/core/src/test/java/org/fuin/objects4j/core/ArchitectureTest.java index 25c42b3..88e43ac 100644 --- a/core/src/test/java/org/fuin/objects4j/core/ArchitectureTest.java +++ b/core/src/test/java/org/fuin/objects4j/core/ArchitectureTest.java @@ -48,7 +48,8 @@ class ArchitectureTest { .resideInAnyPackage(COMMON_PACKAGE, UI_PACKAGE, CORE_PACKAGE, "java.lang..", "java.util..", "java.io..", "java.text..", "java.security..", "java.math..", "java.time..", "jakarta.mail..", - "jakarta.validation..", "jakarta.annotation..", "jakarta.enterprise.inject.."); + "jakarta.validation..", "jakarta.annotation..", "jakarta.enterprise.inject..", + "javax.annotation.concurrent"); } diff --git a/jackson/pom.xml b/jackson/pom.xml new file mode 100644 index 0000000..0416206 --- /dev/null +++ b/jackson/pom.xml @@ -0,0 +1,162 @@ + + + 4.0.0 + + + org.fuin.objects4j + objects4j-parent + 0.10.0-SNAPSHOT + ../pom.xml + + + objects4j-jackson + + + + + + + org.fuin.objects4j + objects4j-common + + + + org.fuin.objects4j + objects4j-core + + + + com.fasterxml.jackson.core + jackson-databind + + + + com.fasterxml.jackson.core + jackson-core + + + + jakarta.validation + jakarta.validation-api + + + + com.google.code.findbugs + jsr305 + + + + + + org.junit.jupiter + junit-jupiter-api + test + + + + org.assertj + assertj-core + test + + + + com.tngtech.archunit + archunit + test + + + + com.tngtech.archunit + archunit-junit5 + test + + + + jakarta.el + jakarta.el-api + test + + + + org.glassfish + jakarta.el + test + + + + org.hibernate.validator + hibernate-validator + test + + + + com.fasterxml.jackson.core + jackson-annotations + test + + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + org.apache.maven.plugins + maven-source-plugin + + + + org.apache.maven.plugins + maven-javadoc-plugin + + + + io.smallrye + jandex-maven-plugin + + + + org.apache.maven.plugins + maven-jdeps-plugin + + + + org.apache.maven.plugins + maven-surefire-plugin + + + + org.jacoco + jacoco-maven-plugin + + + + org.apache.maven.plugins + maven-dependency-plugin + + + jakarta.el:jakarta.el-api + org.glassfish:jakarta.el + org.hibernate.validator:hibernate-validator + org.glassfish.jaxb:jaxb-runtime + com.tngtech.archunit:archunit-junit5 + + + com.tngtech.archunit:archunit-junit5-api + + + + + + + + + diff --git a/jackson/src/main/java/org/fuin/objects4j/jackson/CurrencyAmountJacksonDeserializer.java b/jackson/src/main/java/org/fuin/objects4j/jackson/CurrencyAmountJacksonDeserializer.java new file mode 100644 index 0000000..ff42338 --- /dev/null +++ b/jackson/src/main/java/org/fuin/objects4j/jackson/CurrencyAmountJacksonDeserializer.java @@ -0,0 +1,37 @@ +/** + * Copyright (C) 2015 Michael Schnell. All rights reserved. + * http://www.fuin.org/ + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see http://www.gnu.org/licenses/. + */ +package org.fuin.objects4j.jackson; + +import org.fuin.objects4j.core.CurrencyAmount; + +import javax.annotation.concurrent.ThreadSafe; + +/** + * Converts a String to a {@link CurrencyAmount}. + */ +@ThreadSafe +public final class CurrencyAmountJacksonDeserializer extends ValueObjectStringJacksonDeserializer { + + /** + * Default constructor. + */ + public CurrencyAmountJacksonDeserializer() { + super(CurrencyAmount.class, CurrencyAmount::valueOf); + } + +} diff --git a/jackson/src/main/java/org/fuin/objects4j/jackson/CurrencyAmountJacksonSerializer.java b/jackson/src/main/java/org/fuin/objects4j/jackson/CurrencyAmountJacksonSerializer.java new file mode 100644 index 0000000..8a1bd4c --- /dev/null +++ b/jackson/src/main/java/org/fuin/objects4j/jackson/CurrencyAmountJacksonSerializer.java @@ -0,0 +1,37 @@ +/** + * Copyright (C) 2015 Michael Schnell. All rights reserved. + * http://www.fuin.org/ + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see http://www.gnu.org/licenses/. + */ +package org.fuin.objects4j.jackson; + +import org.fuin.objects4j.core.CurrencyAmount; + +import javax.annotation.concurrent.ThreadSafe; + +/** + * Converts a {@link CurrencyAmount} to String. + */ +@ThreadSafe +public final class CurrencyAmountJacksonSerializer extends ValueObjectStringJacksonSerializer { + + /** + * Default constructor. + */ + public CurrencyAmountJacksonSerializer() { + super(CurrencyAmount.class, CurrencyAmount::valueOf); + } + +} diff --git a/jackson/src/main/java/org/fuin/objects4j/jackson/CurrencyJacksonDeserializer.java b/jackson/src/main/java/org/fuin/objects4j/jackson/CurrencyJacksonDeserializer.java new file mode 100644 index 0000000..7d66215 --- /dev/null +++ b/jackson/src/main/java/org/fuin/objects4j/jackson/CurrencyJacksonDeserializer.java @@ -0,0 +1,55 @@ +/** + * Copyright (C) 2015 Michael Schnell. All rights reserved. + * http://www.fuin.org/ + *

+ * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. + *

+ * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + *

+ * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see http://www.gnu.org/licenses/. + */ +package org.fuin.objects4j.jackson; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonToken; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.deser.std.StdDeserializer; + +import javax.annotation.concurrent.ThreadSafe; +import java.io.IOException; +import java.util.Currency; + +/** + * Converts a String into a {@link Currency}. + */ +@ThreadSafe +public final class CurrencyJacksonDeserializer extends StdDeserializer { + + /** + * Default constructor. + */ + public CurrencyJacksonDeserializer() { + super(Currency.class); + } + + @Override + public Currency deserialize(JsonParser parser, DeserializationContext context) throws IOException { + final JsonToken currentToken = parser.getCurrentToken(); + if (currentToken.equals(JsonToken.VALUE_STRING)) { + final String value = parser.getText().trim(); + return Currency.getInstance(value); + } + if (currentToken.equals(JsonToken.VALUE_NULL)) { + return null; + } + return (Currency) context.handleUnexpectedToken(handledType(), parser); + } + +} diff --git a/jackson/src/main/java/org/fuin/objects4j/jackson/CurrencyJacksonSerializer.java b/jackson/src/main/java/org/fuin/objects4j/jackson/CurrencyJacksonSerializer.java new file mode 100644 index 0000000..2c682ea --- /dev/null +++ b/jackson/src/main/java/org/fuin/objects4j/jackson/CurrencyJacksonSerializer.java @@ -0,0 +1,51 @@ +/** + * Copyright (C) 2015 Michael Schnell. All rights reserved. + * http://www.fuin.org/ + *

+ * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. + *

+ * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + *

+ * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see http://www.gnu.org/licenses/. + */ +package org.fuin.objects4j.jackson; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.ser.std.StdSerializer; + +import javax.annotation.concurrent.ThreadSafe; +import java.io.IOException; +import java.util.Currency; + +/** + * Converts a {@link Currency}. + */ +@ThreadSafe +public final class CurrencyJacksonSerializer extends StdSerializer { + + /** + * Default constructor. + */ + public CurrencyJacksonSerializer() { + super(Currency.class); + } + + @Override + public void serialize(Currency value, JsonGenerator gen, SerializerProvider provider) throws IOException { + if (value == null) { + gen.writeNull(); + } else { + gen.writeString(value.toString()); + } + } + + +} diff --git a/jackson/src/main/java/org/fuin/objects4j/jackson/DayOfTheWeekJacksonDeserializer.java b/jackson/src/main/java/org/fuin/objects4j/jackson/DayOfTheWeekJacksonDeserializer.java new file mode 100644 index 0000000..78047e7 --- /dev/null +++ b/jackson/src/main/java/org/fuin/objects4j/jackson/DayOfTheWeekJacksonDeserializer.java @@ -0,0 +1,37 @@ +/** + * Copyright (C) 2015 Michael Schnell. All rights reserved. + * http://www.fuin.org/ + *

+ * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. + *

+ * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + *

+ * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see http://www.gnu.org/licenses/. + */ +package org.fuin.objects4j.jackson; + +import org.fuin.objects4j.core.DayOfTheWeek; + +import javax.annotation.concurrent.ThreadSafe; + +/** + * Converts a String to a {@link DayOfTheWeek}. + */ +@ThreadSafe +public final class DayOfTheWeekJacksonDeserializer extends ValueObjectStringJacksonDeserializer { + + /** + * Default constructor. + */ + public DayOfTheWeekJacksonDeserializer() { + super(DayOfTheWeek.class, DayOfTheWeek::valueOf); + } + +} diff --git a/jackson/src/main/java/org/fuin/objects4j/jackson/DayOfTheWeekJacksonSerializer.java b/jackson/src/main/java/org/fuin/objects4j/jackson/DayOfTheWeekJacksonSerializer.java new file mode 100644 index 0000000..491e7d8 --- /dev/null +++ b/jackson/src/main/java/org/fuin/objects4j/jackson/DayOfTheWeekJacksonSerializer.java @@ -0,0 +1,37 @@ +/** + * Copyright (C) 2015 Michael Schnell. All rights reserved. + * http://www.fuin.org/ + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see http://www.gnu.org/licenses/. + */ +package org.fuin.objects4j.jackson; + +import org.fuin.objects4j.core.DayOfTheWeek; + +import javax.annotation.concurrent.ThreadSafe; + +/** + * Converts a {@link DayOfTheWeek} from/to String. + */ +@ThreadSafe +public final class DayOfTheWeekJacksonSerializer extends ValueObjectStringJacksonSerializer { + + /** + * Default constructor. + */ + public DayOfTheWeekJacksonSerializer() { + super(DayOfTheWeek.class, DayOfTheWeek::valueOf); + } + +} diff --git a/jackson/src/main/java/org/fuin/objects4j/jackson/DayOpeningHoursJacksonDeserializer.java b/jackson/src/main/java/org/fuin/objects4j/jackson/DayOpeningHoursJacksonDeserializer.java new file mode 100644 index 0000000..9a73c38 --- /dev/null +++ b/jackson/src/main/java/org/fuin/objects4j/jackson/DayOpeningHoursJacksonDeserializer.java @@ -0,0 +1,37 @@ +/** + * Copyright (C) 2015 Michael Schnell. All rights reserved. + * http://www.fuin.org/ + *

+ * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. + *

+ * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + *

+ * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see http://www.gnu.org/licenses/. + */ +package org.fuin.objects4j.jackson; + +import org.fuin.objects4j.core.DayOpeningHours; + +import javax.annotation.concurrent.ThreadSafe; + +/** + * Converts a String to a {@link DayOpeningHours}. + */ +@ThreadSafe +public final class DayOpeningHoursJacksonDeserializer extends ValueObjectStringJacksonDeserializer { + + /** + * Default constructor. + */ + public DayOpeningHoursJacksonDeserializer() { + super(DayOpeningHours.class, DayOpeningHours::valueOf); + } + +} diff --git a/jackson/src/main/java/org/fuin/objects4j/jackson/DayOpeningHoursJacksonSerializer.java b/jackson/src/main/java/org/fuin/objects4j/jackson/DayOpeningHoursJacksonSerializer.java new file mode 100644 index 0000000..d3b8791 --- /dev/null +++ b/jackson/src/main/java/org/fuin/objects4j/jackson/DayOpeningHoursJacksonSerializer.java @@ -0,0 +1,37 @@ +/** + * Copyright (C) 2015 Michael Schnell. All rights reserved. + * http://www.fuin.org/ + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see http://www.gnu.org/licenses/. + */ +package org.fuin.objects4j.jackson; + +import org.fuin.objects4j.core.DayOpeningHours; + +import javax.annotation.concurrent.ThreadSafe; + +/** + * Converts a {@link DayOpeningHours} into a String. + */ +@ThreadSafe +public final class DayOpeningHoursJacksonSerializer extends ValueObjectStringJacksonSerializer { + + /** + * Default constructor. + */ + public DayOpeningHoursJacksonSerializer() { + super(DayOpeningHours.class, DayOpeningHours::valueOf); + } + +} diff --git a/jackson/src/main/java/org/fuin/objects4j/jackson/EmailAddressJacksonDeserializer.java b/jackson/src/main/java/org/fuin/objects4j/jackson/EmailAddressJacksonDeserializer.java new file mode 100644 index 0000000..b2a58b9 --- /dev/null +++ b/jackson/src/main/java/org/fuin/objects4j/jackson/EmailAddressJacksonDeserializer.java @@ -0,0 +1,37 @@ +/** + * Copyright (C) 2015 Michael Schnell. All rights reserved. + * http://www.fuin.org/ + *

+ * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. + *

+ * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + *

+ * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see http://www.gnu.org/licenses/. + */ +package org.fuin.objects4j.jackson; + +import org.fuin.objects4j.core.EmailAddress; + +import javax.annotation.concurrent.ThreadSafe; + +/** + * Converts a String to a {@link EmailAddress}. + */ +@ThreadSafe +public final class EmailAddressJacksonDeserializer extends ValueObjectStringJacksonDeserializer { + + /** + * Default constructor. + */ + public EmailAddressJacksonDeserializer() { + super(EmailAddress.class, EmailAddress::valueOf); + } + +} diff --git a/jackson/src/main/java/org/fuin/objects4j/jackson/EmailAddressJacksonSerializer.java b/jackson/src/main/java/org/fuin/objects4j/jackson/EmailAddressJacksonSerializer.java new file mode 100644 index 0000000..e6765cc --- /dev/null +++ b/jackson/src/main/java/org/fuin/objects4j/jackson/EmailAddressJacksonSerializer.java @@ -0,0 +1,37 @@ +/** + * Copyright (C) 2015 Michael Schnell. All rights reserved. + * http://www.fuin.org/ + *

+ * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. + *

+ * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + *

+ * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see http://www.gnu.org/licenses/. + */ +package org.fuin.objects4j.jackson; + +import org.fuin.objects4j.core.EmailAddress; + +import javax.annotation.concurrent.ThreadSafe; + +/** + * Converts a {@link EmailAddress} into a String. + */ +@ThreadSafe +public final class EmailAddressJacksonSerializer extends ValueObjectStringJacksonSerializer { + + /** + * Default constructor. + */ + public EmailAddressJacksonSerializer() { + super(EmailAddress.class, EmailAddress::valueOf); + } + +} diff --git a/jsonb/src/main/java/org/fuin/objects4j/jsonb/PasswordJsonbAdapter.java b/jackson/src/main/java/org/fuin/objects4j/jackson/HourJacksonDeserializer.java similarity index 75% rename from jsonb/src/main/java/org/fuin/objects4j/jsonb/PasswordJsonbAdapter.java rename to jackson/src/main/java/org/fuin/objects4j/jackson/HourJacksonDeserializer.java index 69b62fb..d655365 100644 --- a/jsonb/src/main/java/org/fuin/objects4j/jsonb/PasswordJsonbAdapter.java +++ b/jackson/src/main/java/org/fuin/objects4j/jackson/HourJacksonDeserializer.java @@ -15,23 +15,23 @@ * You should have received a copy of the GNU Lesser General Public License * along with this library. If not, see http://www.gnu.org/licenses/. */ -package org.fuin.objects4j.jsonb; +package org.fuin.objects4j.jackson; -import org.fuin.objects4j.core.Password; +import org.fuin.objects4j.core.Hour; import javax.annotation.concurrent.ThreadSafe; /** - * Converts a {@link Password} from/to String. + * Converts a String to a {@link Hour}. */ @ThreadSafe -public class PasswordJsonbAdapter extends ValueObjectStringJsonbAdapter { +public final class HourJacksonDeserializer extends ValueObjectStringJacksonDeserializer { /** * Default constructor. */ - public PasswordJsonbAdapter() { - super(Password::valueOf); + public HourJacksonDeserializer() { + super(Hour.class, Hour::valueOf); } } diff --git a/jaxb/src/main/java/org/fuin/objects4j/jaxb/PasswordXmlAdapter.java b/jackson/src/main/java/org/fuin/objects4j/jackson/HourJacksonSerializer.java similarity index 75% rename from jaxb/src/main/java/org/fuin/objects4j/jaxb/PasswordXmlAdapter.java rename to jackson/src/main/java/org/fuin/objects4j/jackson/HourJacksonSerializer.java index 008da75..d34c78e 100644 --- a/jaxb/src/main/java/org/fuin/objects4j/jaxb/PasswordXmlAdapter.java +++ b/jackson/src/main/java/org/fuin/objects4j/jackson/HourJacksonSerializer.java @@ -15,23 +15,23 @@ * You should have received a copy of the GNU Lesser General Public License * along with this library. If not, see http://www.gnu.org/licenses/. */ -package org.fuin.objects4j.jaxb; +package org.fuin.objects4j.jackson; -import org.fuin.objects4j.core.Password; +import org.fuin.objects4j.core.Hour; import javax.annotation.concurrent.ThreadSafe; /** - * Converts a {@link Password} from/to String. + * Converts a {@link Hour} into a String. */ @ThreadSafe -public class PasswordXmlAdapter extends ValueObjectStringXmlAdapter { +public final class HourJacksonSerializer extends ValueObjectStringJacksonSerializer { /** * Default constructor. */ - public PasswordXmlAdapter() { - super(Password::valueOf); + public HourJacksonSerializer() { + super(Hour.class, Hour::valueOf); } } diff --git a/jackson/src/main/java/org/fuin/objects4j/jackson/HourRangeJacksonDeserializer.java b/jackson/src/main/java/org/fuin/objects4j/jackson/HourRangeJacksonDeserializer.java new file mode 100644 index 0000000..cae4e3c --- /dev/null +++ b/jackson/src/main/java/org/fuin/objects4j/jackson/HourRangeJacksonDeserializer.java @@ -0,0 +1,37 @@ +/** + * Copyright (C) 2015 Michael Schnell. All rights reserved. + * http://www.fuin.org/ + *

+ * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. + *

+ * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + *

+ * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see http://www.gnu.org/licenses/. + */ +package org.fuin.objects4j.jackson; + +import org.fuin.objects4j.core.HourRange; + +import javax.annotation.concurrent.ThreadSafe; + +/** + * Converts a String to a {@link HourRange}. + */ +@ThreadSafe +public final class HourRangeJacksonDeserializer extends ValueObjectStringJacksonDeserializer { + + /** + * Default constructor. + */ + public HourRangeJacksonDeserializer() { + super(HourRange.class, HourRange::valueOf); + } + +} diff --git a/jackson/src/main/java/org/fuin/objects4j/jackson/HourRangeJacksonSerializer.java b/jackson/src/main/java/org/fuin/objects4j/jackson/HourRangeJacksonSerializer.java new file mode 100644 index 0000000..8851bc8 --- /dev/null +++ b/jackson/src/main/java/org/fuin/objects4j/jackson/HourRangeJacksonSerializer.java @@ -0,0 +1,37 @@ +/** + * Copyright (C) 2015 Michael Schnell. All rights reserved. + * http://www.fuin.org/ + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see http://www.gnu.org/licenses/. + */ +package org.fuin.objects4j.jackson; + +import org.fuin.objects4j.core.HourRange; + +import javax.annotation.concurrent.ThreadSafe; + +/** + * Converts a {@link HourRange} into a String. + */ +@ThreadSafe +public final class HourRangeJacksonSerializer extends ValueObjectStringJacksonSerializer { + + /** + * Default constructor. + */ + public HourRangeJacksonSerializer() { + super(HourRange.class, HourRange::valueOf); + } + +} diff --git a/jackson/src/main/java/org/fuin/objects4j/jackson/HourRangesJacksonDeserializer.java b/jackson/src/main/java/org/fuin/objects4j/jackson/HourRangesJacksonDeserializer.java new file mode 100644 index 0000000..4e13e35 --- /dev/null +++ b/jackson/src/main/java/org/fuin/objects4j/jackson/HourRangesJacksonDeserializer.java @@ -0,0 +1,37 @@ +/** + * Copyright (C) 2015 Michael Schnell. All rights reserved. + * http://www.fuin.org/ + *

+ * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. + *

+ * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + *

+ * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see http://www.gnu.org/licenses/. + */ +package org.fuin.objects4j.jackson; + +import org.fuin.objects4j.core.HourRanges; + +import javax.annotation.concurrent.ThreadSafe; + +/** + * Converts a String to a {@link HourRanges}. + */ +@ThreadSafe +public final class HourRangesJacksonDeserializer extends ValueObjectStringJacksonDeserializer { + + /** + * Default constructor. + */ + public HourRangesJacksonDeserializer() { + super(HourRanges.class, HourRanges::valueOf); + } + +} diff --git a/jackson/src/main/java/org/fuin/objects4j/jackson/HourRangesJacksonSerializer.java b/jackson/src/main/java/org/fuin/objects4j/jackson/HourRangesJacksonSerializer.java new file mode 100644 index 0000000..52b4d03 --- /dev/null +++ b/jackson/src/main/java/org/fuin/objects4j/jackson/HourRangesJacksonSerializer.java @@ -0,0 +1,37 @@ +/** + * Copyright (C) 2015 Michael Schnell. All rights reserved. + * http://www.fuin.org/ + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see http://www.gnu.org/licenses/. + */ +package org.fuin.objects4j.jackson; + +import org.fuin.objects4j.core.HourRanges; + +import javax.annotation.concurrent.ThreadSafe; + +/** + * Converts {@link HourRanges} into a String. + */ +@ThreadSafe +public final class HourRangesJacksonSerializer extends ValueObjectStringJacksonSerializer { + + /** + * Default constructor. + */ + public HourRangesJacksonSerializer() { + super(HourRanges.class, HourRanges::valueOf); + } + +} diff --git a/jackson/src/main/java/org/fuin/objects4j/jackson/LocaleJacksonDeserializer.java b/jackson/src/main/java/org/fuin/objects4j/jackson/LocaleJacksonDeserializer.java new file mode 100644 index 0000000..e12eb6c --- /dev/null +++ b/jackson/src/main/java/org/fuin/objects4j/jackson/LocaleJacksonDeserializer.java @@ -0,0 +1,57 @@ +/** + * Copyright (C) 2015 Michael Schnell. All rights reserved. + * http://www.fuin.org/ + *

+ * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. + *

+ * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + *

+ * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see http://www.gnu.org/licenses/. + */ +package org.fuin.objects4j.jackson; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonToken; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.deser.std.StdDeserializer; +import org.fuin.objects4j.core.LocaleHelper; + +import javax.annotation.concurrent.ThreadSafe; +import java.io.IOException; +import java.util.Currency; +import java.util.Locale; + +/** + * Converts a String into a {@link Locale}. + */ +@ThreadSafe +public final class LocaleJacksonDeserializer extends StdDeserializer { + + /** + * Default constructor. + */ + public LocaleJacksonDeserializer() { + super(Currency.class); + } + + @Override + public Locale deserialize(JsonParser parser, DeserializationContext context) throws IOException { + final JsonToken currentToken = parser.getCurrentToken(); + if (currentToken.equals(JsonToken.VALUE_STRING)) { + final String value = parser.getText().trim(); + return LocaleHelper.asLocale(value); + } + if (currentToken.equals(JsonToken.VALUE_NULL)) { + return null; + } + return (Locale) context.handleUnexpectedToken(handledType(), parser); + } + +} diff --git a/jackson/src/main/java/org/fuin/objects4j/jackson/LocaleJacksonSerializer.java b/jackson/src/main/java/org/fuin/objects4j/jackson/LocaleJacksonSerializer.java new file mode 100644 index 0000000..c8ce73d --- /dev/null +++ b/jackson/src/main/java/org/fuin/objects4j/jackson/LocaleJacksonSerializer.java @@ -0,0 +1,50 @@ +/** + * Copyright (C) 2015 Michael Schnell. All rights reserved. + * http://www.fuin.org/ + *

+ * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. + *

+ * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + *

+ * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see http://www.gnu.org/licenses/. + */ +package org.fuin.objects4j.jackson; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.ser.std.StdSerializer; + +import javax.annotation.concurrent.ThreadSafe; +import java.io.IOException; +import java.util.Locale; + +/** + * Converts a {@link Locale} into a String. + */ +@ThreadSafe +public final class LocaleJacksonSerializer extends StdSerializer { + + /** + * Default constructor. + */ + public LocaleJacksonSerializer() { + super(Locale.class); + } + + @Override + public void serialize(Locale value, JsonGenerator gen, SerializerProvider provider) throws IOException { + if (value == null) { + gen.writeNull(); + } else { + gen.writeString(value.toString()); + } + } + +} diff --git a/jackson/src/main/java/org/fuin/objects4j/jackson/MultiDayOfTheWeekJacksonDeserializer.java b/jackson/src/main/java/org/fuin/objects4j/jackson/MultiDayOfTheWeekJacksonDeserializer.java new file mode 100644 index 0000000..6b51b84 --- /dev/null +++ b/jackson/src/main/java/org/fuin/objects4j/jackson/MultiDayOfTheWeekJacksonDeserializer.java @@ -0,0 +1,37 @@ +/** + * Copyright (C) 2015 Michael Schnell. All rights reserved. + * http://www.fuin.org/ + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see http://www.gnu.org/licenses/. + */ +package org.fuin.objects4j.jackson; + +import org.fuin.objects4j.core.MultiDayOfTheWeek; + +import javax.annotation.concurrent.ThreadSafe; + +/** + * Converts String to a {@link MultiDayOfTheWeek}. + */ +@ThreadSafe +public final class MultiDayOfTheWeekJacksonDeserializer extends ValueObjectStringJacksonDeserializer { + + /** + * Default constructor. + */ + public MultiDayOfTheWeekJacksonDeserializer() { + super(MultiDayOfTheWeek.class, MultiDayOfTheWeek::valueOf); + } + +} diff --git a/jackson/src/main/java/org/fuin/objects4j/jackson/MultiDayOfTheWeekJacksonSerializer.java b/jackson/src/main/java/org/fuin/objects4j/jackson/MultiDayOfTheWeekJacksonSerializer.java new file mode 100644 index 0000000..f31a27a --- /dev/null +++ b/jackson/src/main/java/org/fuin/objects4j/jackson/MultiDayOfTheWeekJacksonSerializer.java @@ -0,0 +1,37 @@ +/** + * Copyright (C) 2015 Michael Schnell. All rights reserved. + * http://www.fuin.org/ + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see http://www.gnu.org/licenses/. + */ +package org.fuin.objects4j.jackson; + +import org.fuin.objects4j.core.MultiDayOfTheWeek; + +import javax.annotation.concurrent.ThreadSafe; + +/** + * Converts {@link MultiDayOfTheWeek} into a String. + */ +@ThreadSafe +public final class MultiDayOfTheWeekJacksonSerializer extends ValueObjectStringJacksonSerializer { + + /** + * Default constructor. + */ + public MultiDayOfTheWeekJacksonSerializer() { + super(MultiDayOfTheWeek.class, MultiDayOfTheWeek::valueOf); + } + +} diff --git a/jackson/src/main/java/org/fuin/objects4j/jackson/Objects4JJacksonAdapterModule.java b/jackson/src/main/java/org/fuin/objects4j/jackson/Objects4JJacksonAdapterModule.java new file mode 100644 index 0000000..cab197c --- /dev/null +++ b/jackson/src/main/java/org/fuin/objects4j/jackson/Objects4JJacksonAdapterModule.java @@ -0,0 +1,76 @@ +package org.fuin.objects4j.jackson; + +import com.fasterxml.jackson.core.Version; +import com.fasterxml.jackson.databind.Module; +import com.fasterxml.jackson.databind.module.SimpleDeserializers; +import com.fasterxml.jackson.databind.module.SimpleSerializers; +import org.fuin.objects4j.core.CurrencyAmount; +import org.fuin.objects4j.core.DayOfTheWeek; +import org.fuin.objects4j.core.DayOpeningHours; +import org.fuin.objects4j.core.EmailAddress; +import org.fuin.objects4j.core.Hour; +import org.fuin.objects4j.core.HourRange; +import org.fuin.objects4j.core.HourRanges; +import org.fuin.objects4j.core.MultiDayOfTheWeek; +import org.fuin.objects4j.core.PasswordSha512; +import org.fuin.objects4j.core.UserName; +import org.fuin.objects4j.core.WeeklyOpeningHours; + +import java.util.Currency; +import java.util.Locale; +import java.util.UUID; + +/** + * Module that registers the adapters for the package. + */ +public class Objects4JJacksonAdapterModule extends Module { + + @Override + public String getModuleName() { + return "Objects4JModule"; + } + + @Override + public void setupModule(Module.SetupContext context) { + + final SimpleSerializers serializers = new SimpleSerializers(); + serializers.addSerializer(new CurrencyAmountJacksonSerializer()); + serializers.addSerializer(new CurrencyJacksonSerializer()); + serializers.addSerializer(new DayOfTheWeekJacksonSerializer()); + serializers.addSerializer(new DayOpeningHoursJacksonSerializer()); + serializers.addSerializer(new EmailAddressJacksonSerializer()); + serializers.addSerializer(new HourJacksonSerializer()); + serializers.addSerializer(new HourRangeJacksonSerializer()); + serializers.addSerializer(new HourRangesJacksonSerializer()); + serializers.addSerializer(new LocaleJacksonSerializer()); + serializers.addSerializer(new MultiDayOfTheWeekJacksonSerializer()); + serializers.addSerializer(new PasswordSha512JacksonSerializer()); + serializers.addSerializer(new UserNameJacksonSerializer()); + serializers.addSerializer(new UUIDJacksonSerializer()); + serializers.addSerializer(new WeeklyOpeningHoursJacksonSerializer()); + context.addSerializers(serializers); + + final SimpleDeserializers deserializers = new SimpleDeserializers(); + deserializers.addDeserializer(CurrencyAmount.class, new CurrencyAmountJacksonDeserializer()); + deserializers.addDeserializer(Currency.class, new CurrencyJacksonDeserializer()); + deserializers.addDeserializer(DayOfTheWeek.class, new DayOfTheWeekJacksonDeserializer()); + deserializers.addDeserializer(DayOpeningHours.class, new DayOpeningHoursJacksonDeserializer()); + deserializers.addDeserializer(EmailAddress.class, new EmailAddressJacksonDeserializer()); + deserializers.addDeserializer(Hour.class, new HourJacksonDeserializer()); + deserializers.addDeserializer(HourRange.class, new HourRangeJacksonDeserializer()); + deserializers.addDeserializer(HourRanges.class, new HourRangesJacksonDeserializer()); + deserializers.addDeserializer(Locale.class, new LocaleJacksonDeserializer()); + deserializers.addDeserializer(MultiDayOfTheWeek.class, new MultiDayOfTheWeekJacksonDeserializer()); + deserializers.addDeserializer(PasswordSha512.class, new PasswordSha512JacksonDeserializer()); + deserializers.addDeserializer(UserName.class, new UserNameJacksonDeserializer()); + deserializers.addDeserializer(UUID.class, new UUIDJacksonDeserializer()); + deserializers.addDeserializer(WeeklyOpeningHours.class, new WeeklyOpeningHoursJacksonDeserializer()); + context.addDeserializers(deserializers); + } + + @Override + public Version version() { + return new Version(0, 10, 0, "SNAPSHOT"); + } + +} \ No newline at end of file diff --git a/jackson/src/main/java/org/fuin/objects4j/jackson/PasswordSha512JacksonDeserializer.java b/jackson/src/main/java/org/fuin/objects4j/jackson/PasswordSha512JacksonDeserializer.java new file mode 100644 index 0000000..a564b67 --- /dev/null +++ b/jackson/src/main/java/org/fuin/objects4j/jackson/PasswordSha512JacksonDeserializer.java @@ -0,0 +1,37 @@ +/** + * Copyright (C) 2015 Michael Schnell. All rights reserved. + * http://www.fuin.org/ + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see http://www.gnu.org/licenses/. + */ +package org.fuin.objects4j.jackson; + +import org.fuin.objects4j.core.PasswordSha512; + +import javax.annotation.concurrent.ThreadSafe; + +/** + * Converts a String to a {@link PasswordSha512}. + */ +@ThreadSafe +public class PasswordSha512JacksonDeserializer extends ValueObjectStringJacksonDeserializer { + + /** + * Default constructor. + */ + public PasswordSha512JacksonDeserializer() { + super(PasswordSha512.class, PasswordSha512::valueOf); + } + +} diff --git a/jackson/src/main/java/org/fuin/objects4j/jackson/PasswordSha512JacksonSerializer.java b/jackson/src/main/java/org/fuin/objects4j/jackson/PasswordSha512JacksonSerializer.java new file mode 100644 index 0000000..b4b0c64 --- /dev/null +++ b/jackson/src/main/java/org/fuin/objects4j/jackson/PasswordSha512JacksonSerializer.java @@ -0,0 +1,37 @@ +/** + * Copyright (C) 2015 Michael Schnell. All rights reserved. + * http://www.fuin.org/ + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see http://www.gnu.org/licenses/. + */ +package org.fuin.objects4j.jackson; + +import org.fuin.objects4j.core.PasswordSha512; + +import javax.annotation.concurrent.ThreadSafe; + +/** + * Converts a {@link PasswordSha512} into a String. + */ +@ThreadSafe +public class PasswordSha512JacksonSerializer extends ValueObjectStringJacksonSerializer { + + /** + * Default constructor. + */ + public PasswordSha512JacksonSerializer() { + super(PasswordSha512.class, PasswordSha512::valueOf); + } + +} diff --git a/jackson/src/main/java/org/fuin/objects4j/jackson/UUIDJacksonDeserializer.java b/jackson/src/main/java/org/fuin/objects4j/jackson/UUIDJacksonDeserializer.java new file mode 100644 index 0000000..583ef11 --- /dev/null +++ b/jackson/src/main/java/org/fuin/objects4j/jackson/UUIDJacksonDeserializer.java @@ -0,0 +1,55 @@ +/** + * Copyright (C) 2015 Michael Schnell. All rights reserved. + * http://www.fuin.org/ + *

+ * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. + *

+ * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + *

+ * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see http://www.gnu.org/licenses/. + */ +package org.fuin.objects4j.jackson; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonToken; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.deser.std.StdDeserializer; + +import javax.annotation.concurrent.ThreadSafe; +import java.io.IOException; +import java.util.UUID; + +/** + * Converts a String into a {@link UUID}. + */ +@ThreadSafe +public final class UUIDJacksonDeserializer extends StdDeserializer { + + /** + * Default constructor. + */ + public UUIDJacksonDeserializer() { + super(UUID.class); + } + + @Override + public UUID deserialize(JsonParser parser, DeserializationContext context) throws IOException { + final JsonToken currentToken = parser.getCurrentToken(); + if (currentToken.equals(JsonToken.VALUE_STRING)) { + final String value = parser.getText().trim(); + return UUID.fromString(value); + } + if (currentToken.equals(JsonToken.VALUE_NULL)) { + return null; + } + return (UUID) context.handleUnexpectedToken(handledType(), parser); + } + +} diff --git a/jackson/src/main/java/org/fuin/objects4j/jackson/UUIDJacksonSerializer.java b/jackson/src/main/java/org/fuin/objects4j/jackson/UUIDJacksonSerializer.java new file mode 100644 index 0000000..307ed50 --- /dev/null +++ b/jackson/src/main/java/org/fuin/objects4j/jackson/UUIDJacksonSerializer.java @@ -0,0 +1,50 @@ +/** + * Copyright (C) 2015 Michael Schnell. All rights reserved. + * http://www.fuin.org/ + *

+ * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. + *

+ * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + *

+ * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see http://www.gnu.org/licenses/. + */ +package org.fuin.objects4j.jackson; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.ser.std.StdSerializer; + +import javax.annotation.concurrent.ThreadSafe; +import java.io.IOException; +import java.util.UUID; + +/** + * Converts a {@link UUID} into a String. + */ +@ThreadSafe +public final class UUIDJacksonSerializer extends StdSerializer { + + /** + * Default constructor. + */ + public UUIDJacksonSerializer() { + super(UUID.class); + } + + @Override + public void serialize(UUID value, JsonGenerator gen, SerializerProvider provider) throws IOException { + if (value == null) { + gen.writeNull(); + } else { + gen.writeString(value.toString()); + } + } + +} diff --git a/jackson/src/main/java/org/fuin/objects4j/jackson/UserNameJacksonDeserializer.java b/jackson/src/main/java/org/fuin/objects4j/jackson/UserNameJacksonDeserializer.java new file mode 100644 index 0000000..f335673 --- /dev/null +++ b/jackson/src/main/java/org/fuin/objects4j/jackson/UserNameJacksonDeserializer.java @@ -0,0 +1,37 @@ +/** + * Copyright (C) 2015 Michael Schnell. All rights reserved. + * http://www.fuin.org/ + *

+ * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. + *

+ * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + *

+ * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see http://www.gnu.org/licenses/. + */ +package org.fuin.objects4j.jackson; + +import org.fuin.objects4j.core.UserName; + +import javax.annotation.concurrent.ThreadSafe; + +/** + * Converts a String to a {@link UserName}. + */ +@ThreadSafe +public final class UserNameJacksonDeserializer extends ValueObjectStringJacksonDeserializer { + + /** + * Default constructor. + */ + public UserNameJacksonDeserializer() { + super(UserName.class, UserName::valueOf); + } + +} diff --git a/jackson/src/main/java/org/fuin/objects4j/jackson/UserNameJacksonSerializer.java b/jackson/src/main/java/org/fuin/objects4j/jackson/UserNameJacksonSerializer.java new file mode 100644 index 0000000..49e7c87 --- /dev/null +++ b/jackson/src/main/java/org/fuin/objects4j/jackson/UserNameJacksonSerializer.java @@ -0,0 +1,37 @@ +/** + * Copyright (C) 2015 Michael Schnell. All rights reserved. + * http://www.fuin.org/ + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see http://www.gnu.org/licenses/. + */ +package org.fuin.objects4j.jackson; + +import org.fuin.objects4j.core.UserName; + +import javax.annotation.concurrent.ThreadSafe; + +/** + * Converts {@link UserName} into a String. + */ +@ThreadSafe +public final class UserNameJacksonSerializer extends ValueObjectStringJacksonSerializer { + + /** + * Default constructor. + */ + public UserNameJacksonSerializer() { + super(UserName.class, UserName::valueOf); + } + +} diff --git a/jackson/src/main/java/org/fuin/objects4j/jackson/ValueObjectStringJacksonDeserializer.java b/jackson/src/main/java/org/fuin/objects4j/jackson/ValueObjectStringJacksonDeserializer.java new file mode 100644 index 0000000..920d900 --- /dev/null +++ b/jackson/src/main/java/org/fuin/objects4j/jackson/ValueObjectStringJacksonDeserializer.java @@ -0,0 +1,65 @@ +/** + * Copyright (C) 2015 Michael Schnell. All rights reserved. + * http://www.fuin.org/ + *

+ * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. + *

+ * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + *

+ * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see http://www.gnu.org/licenses/. + */ +package org.fuin.objects4j.jackson; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonToken; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.deser.std.StdDeserializer; +import jakarta.validation.constraints.NotNull; +import org.fuin.objects4j.common.Contract; +import org.fuin.objects4j.core.AsStringCapable; +import org.fuin.objects4j.core.ValueOfCapable; + +import java.io.IOException; + +/** + * Converts a string into a type. + * + * @param Type to convert. + */ +public abstract class ValueObjectStringJacksonDeserializer extends StdDeserializer { + + private final ValueOfCapable vop; + + /** + * Constructor with mandatory data. + * + * @param vop Provides a valueOf method. + */ + public ValueObjectStringJacksonDeserializer(@NotNull final Class clasz, @NotNull final ValueOfCapable vop) { + super(clasz); + Contract.requireArgNotNull("vop", vop); + this.vop = vop; + } + + @Override + @SuppressWarnings("unchecked") + public TYPE deserialize(JsonParser parser, DeserializationContext context) throws IOException { + final JsonToken currentToken = parser.getCurrentToken(); + if (currentToken.equals(JsonToken.VALUE_STRING)) { + final String value = parser.getText().trim(); + return vop.valueOf(value); + } + if (currentToken.equals(JsonToken.VALUE_NULL)) { + return null; + } + return (TYPE) context.handleUnexpectedToken(handledType(), parser); + } + +} diff --git a/jackson/src/main/java/org/fuin/objects4j/jackson/ValueObjectStringJacksonSerializer.java b/jackson/src/main/java/org/fuin/objects4j/jackson/ValueObjectStringJacksonSerializer.java new file mode 100644 index 0000000..e1d5041 --- /dev/null +++ b/jackson/src/main/java/org/fuin/objects4j/jackson/ValueObjectStringJacksonSerializer.java @@ -0,0 +1,59 @@ +/** + * Copyright (C) 2015 Michael Schnell. All rights reserved. + * http://www.fuin.org/ + *

+ * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. + *

+ * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + *

+ * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see http://www.gnu.org/licenses/. + */ +package org.fuin.objects4j.jackson; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.ser.std.StdSerializer; +import jakarta.validation.constraints.NotNull; +import org.fuin.objects4j.common.Contract; +import org.fuin.objects4j.core.AsStringCapable; +import org.fuin.objects4j.core.ValueOfCapable; + +import java.io.IOException; + +/** + * Converts a type into a string and back. + * + * @param Type to convert. + */ +public abstract class ValueObjectStringJacksonSerializer extends StdSerializer { + + private final ValueOfCapable vop; + + /** + * Constructor with mandatory data. + * + * @param vop Provides a valueOf method. + */ + public ValueObjectStringJacksonSerializer(@NotNull final Class clasz, @NotNull final ValueOfCapable vop) { + super(clasz); + Contract.requireArgNotNull("vop", vop); + this.vop = vop; + } + + @Override + public void serialize(TYPE value, JsonGenerator gen, SerializerProvider provider) throws IOException { + if (value == null) { + gen.writeNull(); + } else { + gen.writeString(value.asString()); + } + } + +} diff --git a/jackson/src/main/java/org/fuin/objects4j/jackson/WeeklyOpeningHoursJacksonDeserializer.java b/jackson/src/main/java/org/fuin/objects4j/jackson/WeeklyOpeningHoursJacksonDeserializer.java new file mode 100644 index 0000000..b79af65 --- /dev/null +++ b/jackson/src/main/java/org/fuin/objects4j/jackson/WeeklyOpeningHoursJacksonDeserializer.java @@ -0,0 +1,37 @@ +/** + * Copyright (C) 2015 Michael Schnell. All rights reserved. + * http://www.fuin.org/ + *

+ * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. + *

+ * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + *

+ * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see http://www.gnu.org/licenses/. + */ +package org.fuin.objects4j.jackson; + +import org.fuin.objects4j.core.WeeklyOpeningHours; + +import javax.annotation.concurrent.ThreadSafe; + +/** + * Converts String to a {@link WeeklyOpeningHours}. + */ +@ThreadSafe +public final class WeeklyOpeningHoursJacksonDeserializer extends ValueObjectStringJacksonDeserializer { + + /** + * Default constructor. + */ + public WeeklyOpeningHoursJacksonDeserializer() { + super(WeeklyOpeningHours.class, WeeklyOpeningHours::valueOf); + } + +} diff --git a/jackson/src/main/java/org/fuin/objects4j/jackson/WeeklyOpeningHoursJacksonSerializer.java b/jackson/src/main/java/org/fuin/objects4j/jackson/WeeklyOpeningHoursJacksonSerializer.java new file mode 100644 index 0000000..ae2766e --- /dev/null +++ b/jackson/src/main/java/org/fuin/objects4j/jackson/WeeklyOpeningHoursJacksonSerializer.java @@ -0,0 +1,37 @@ +/** + * Copyright (C) 2015 Michael Schnell. All rights reserved. + * http://www.fuin.org/ + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see http://www.gnu.org/licenses/. + */ +package org.fuin.objects4j.jackson; + +import org.fuin.objects4j.core.WeeklyOpeningHours; + +import javax.annotation.concurrent.ThreadSafe; + +/** + * Converts {@link WeeklyOpeningHours} into a String. + */ +@ThreadSafe +public final class WeeklyOpeningHoursJacksonSerializer extends ValueObjectStringJacksonSerializer { + + /** + * Default constructor. + */ + public WeeklyOpeningHoursJacksonSerializer() { + super(WeeklyOpeningHours.class, WeeklyOpeningHours::valueOf); + } + +} diff --git a/jackson/src/main/resources/META-INF/services/com.fasterxml.jackson.databind.Module b/jackson/src/main/resources/META-INF/services/com.fasterxml.jackson.databind.Module new file mode 100644 index 0000000..25142a8 --- /dev/null +++ b/jackson/src/main/resources/META-INF/services/com.fasterxml.jackson.databind.Module @@ -0,0 +1 @@ +org.fuin.objects4j.jackson.Objects4JJacksonAdapterModuleTest \ No newline at end of file diff --git a/jackson/src/test/java/org/fuin/objects4j/jackson/AnyStr.java b/jackson/src/test/java/org/fuin/objects4j/jackson/AnyStr.java new file mode 100644 index 0000000..74df60d --- /dev/null +++ b/jackson/src/test/java/org/fuin/objects4j/jackson/AnyStr.java @@ -0,0 +1,49 @@ +package org.fuin.objects4j.jackson; + +import com.tngtech.archunit.junit.ArchIgnore; +import org.fuin.objects4j.common.Contract; +import org.fuin.objects4j.core.AbstractStringValueObject; + +import java.io.Serial; + +/** + * Test implementation for a {@link AbstractStringValueObject}. + */ +@ArchIgnore +public final class AnyStr extends AbstractStringValueObject { + + @Serial + private static final long serialVersionUID = 1L; + + private final String str; + + /** + * Constructor with manadatory data. + * + * @param str + * String. + */ + public AnyStr(final String str) { + super(); + Contract.requireArgNotNull("str", str); + this.str = str; + } + + @Override + public String asBaseType() { + return str; + } + + /** + * Converts a given string into an instance of this class. + * + * @param str + * String to convert. + * + * @return New instance. + */ + public static AnyStr valueOf(String str) { + return new AnyStr(str); + } + +} \ No newline at end of file diff --git a/jackson/src/test/java/org/fuin/objects4j/jackson/AnyStrJacksonDeserializer.java b/jackson/src/test/java/org/fuin/objects4j/jackson/AnyStrJacksonDeserializer.java new file mode 100644 index 0000000..081bc3a --- /dev/null +++ b/jackson/src/test/java/org/fuin/objects4j/jackson/AnyStrJacksonDeserializer.java @@ -0,0 +1,18 @@ +package org.fuin.objects4j.jackson; + +import com.tngtech.archunit.junit.ArchIgnore; + +/** + * Test implementation for a {@link ValueObjectStringJacksonDeserializer}. + */ +@ArchIgnore +public class AnyStrJacksonDeserializer extends ValueObjectStringJacksonDeserializer { + + /** + * Default constructor. + */ + public AnyStrJacksonDeserializer() { + super(AnyStr.class, AnyStr::valueOf); + } + +} \ No newline at end of file diff --git a/jackson/src/test/java/org/fuin/objects4j/jackson/AnyStrJacksonSerializer.java b/jackson/src/test/java/org/fuin/objects4j/jackson/AnyStrJacksonSerializer.java new file mode 100644 index 0000000..38c6536 --- /dev/null +++ b/jackson/src/test/java/org/fuin/objects4j/jackson/AnyStrJacksonSerializer.java @@ -0,0 +1,18 @@ +package org.fuin.objects4j.jackson; + +import com.tngtech.archunit.junit.ArchIgnore; + +/** + * Test implementation for a {@link ValueObjectStringJacksonSerializer}. + */ +@ArchIgnore +public class AnyStrJacksonSerializer extends ValueObjectStringJacksonSerializer { + + /** + * Default constructor. + */ + public AnyStrJacksonSerializer() { + super(AnyStr.class, AnyStr::valueOf); + } + +} \ No newline at end of file diff --git a/jackson/src/test/java/org/fuin/objects4j/jackson/ArchitectureTest.java b/jackson/src/test/java/org/fuin/objects4j/jackson/ArchitectureTest.java new file mode 100644 index 0000000..9bf0407 --- /dev/null +++ b/jackson/src/test/java/org/fuin/objects4j/jackson/ArchitectureTest.java @@ -0,0 +1,55 @@ +/** + * Copyright (C) 2013 Future Invent Informationsmanagement GmbH. All rights + * reserved. + *

+ * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. + *

+ * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + *

+ * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see . + */ +package org.fuin.objects4j.jackson; + +import com.tngtech.archunit.core.importer.ImportOption; +import com.tngtech.archunit.junit.AnalyzeClasses; +import com.tngtech.archunit.junit.ArchTest; +import com.tngtech.archunit.lang.ArchRule; +import org.fuin.objects4j.common.ConstraintViolationException; +import org.fuin.objects4j.core.AbstractIntegerValueObject; + +import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes; +import static com.tngtech.archunit.library.DependencyRules.NO_CLASSES_SHOULD_DEPEND_UPPER_PACKAGES; + +@AnalyzeClasses(packagesOf = ArchitectureTest.class, importOptions = ImportOption.DoNotIncludeTests.class) +class ArchitectureTest { + + private static final String COMMON_PACKAGE = ConstraintViolationException.class.getPackageName(); + + private static final String CORE_PACKAGE = AbstractIntegerValueObject.class.getPackageName(); + + private static final String JACKSON_PACKAGE = CurrencyJacksonSerializer.class.getPackageName(); + + @ArchTest + static final ArchRule no_accesses_to_upper_package = NO_CLASSES_SHOULD_DEPEND_UPPER_PACKAGES; + + @ArchTest + static final ArchRule accesses_only_defined_packages = classes() + .that() + .resideInAPackage(JACKSON_PACKAGE) + .should() + .onlyDependOnClassesThat() + .resideInAnyPackage(JACKSON_PACKAGE, COMMON_PACKAGE, CORE_PACKAGE, + "java.lang..", "java.util..", "java.io", + "jakarta.validation..", "jakarta.annotation..", "com.fasterxml.jackson..", + "javax.annotation.concurrent"); + + +} + diff --git a/jackson/src/test/java/org/fuin/objects4j/jackson/BaseTest.java b/jackson/src/test/java/org/fuin/objects4j/jackson/BaseTest.java new file mode 100644 index 0000000..98ee2d7 --- /dev/null +++ b/jackson/src/test/java/org/fuin/objects4j/jackson/BaseTest.java @@ -0,0 +1,91 @@ +/** + * Copyright (C) 2013 Future Invent Informationsmanagement GmbH. All rights + * reserved. + *

+ * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. + *

+ * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + *

+ * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see . + */ +package org.fuin.objects4j.jackson; + +import com.tngtech.archunit.core.domain.JavaClass; +import com.tngtech.archunit.core.domain.JavaModifier; +import com.tngtech.archunit.junit.AnalyzeClasses; +import com.tngtech.archunit.junit.ArchIgnore; +import com.tngtech.archunit.junit.ArchTest; +import com.tngtech.archunit.lang.ArchCondition; +import com.tngtech.archunit.lang.ArchRule; +import com.tngtech.archunit.lang.ConditionEvents; +import com.tngtech.archunit.lang.SimpleConditionEvent; + +import java.util.Collection; +import java.util.Set; + +import static com.tngtech.archunit.lang.ConditionEvent.createMessage; +import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes; +import static java.util.Collections.emptySet; +import static java.util.stream.Collectors.toSet; + +@AnalyzeClasses(packagesOf = CurrencyAmountJacksonSerializer.class) +public class BaseTest { + + @ArchTest + public static final ArchRule all_classes_should_have_tests = + classes() + .that() + .areTopLevelClasses() + .and().areNotInterfaces() + .and().areNotRecords() + .and().areNotEnums() + .and().doNotHaveModifier(JavaModifier.ABSTRACT) + .and().areNotAnnotatedWith(ArchIgnore.class) + .should(haveACorrespondingClassEndingWithTest()); + + private static ArchCondition haveACorrespondingClassEndingWithTest() { + return new AllTopLevelClassesHaveATestCondition("Test"); + } + + private static class AllTopLevelClassesHaveATestCondition extends ArchCondition { + + private final String suffix; + + private Set testedClassNames; + + public AllTopLevelClassesHaveATestCondition(final String suffix) { + super("have a corresponding test class with suffix '" + suffix + "'"); + this.suffix = suffix; + this.testedClassNames = emptySet(); + } + + @Override + public void init(Collection allClasses) { + testedClassNames = allClasses.stream() + .map(JavaClass::getName) + .filter(className -> className.endsWith(suffix)) + .map(className -> className.substring(0, className.length() - suffix.length())) + .collect(toSet()); + } + + @Override + public void check(JavaClass clazz, ConditionEvents events) { + if (!clazz.getName().endsWith(suffix)) { + boolean satisfied = testedClassNames.contains(clazz.getName()); + String message = createMessage(clazz, "has " + (satisfied ? "a" : "no") + " corresponding test class"); + events.add(new SimpleConditionEvent(clazz, satisfied, message)); + } + } + + } + + +} + diff --git a/jackson/src/test/java/org/fuin/objects4j/jackson/CurrencyAmountJacksonDeserializerTest.java b/jackson/src/test/java/org/fuin/objects4j/jackson/CurrencyAmountJacksonDeserializerTest.java new file mode 100644 index 0000000..b3135bb --- /dev/null +++ b/jackson/src/test/java/org/fuin/objects4j/jackson/CurrencyAmountJacksonDeserializerTest.java @@ -0,0 +1,53 @@ +/** + * Copyright (C) 2013 Future Invent Informationsmanagement GmbH. All rights + * reserved. + *

+ * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. + *

+ * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + *

+ * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see . + */ +package org.fuin.objects4j.jackson; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.fuin.objects4j.core.CurrencyAmount; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +/** + * Test for the {@link CurrencyAmountJacksonDeserializer} class. + */ +class CurrencyAmountJacksonDeserializerTest { + + private static final String JSON = "{\"ca\":\"1234.56 EUR\"}"; + + @Test + void testSerializeDeserializeJackson() throws JsonProcessingException { + + final Data data = JacksonHelper.fromJson(JSON, Data.class); + assertThat(data.currencyAmount).isEqualTo(new CurrencyAmount("1234.56", "EUR")); + + } + + @Test + void testDeserializeErrorJackson() { + + final String invalidJsonData = "{\"ca\":\"1234.56\"}"; + assertThatThrownBy(() -> JacksonHelper.fromJson(invalidJsonData, Data.class)) + .hasRootCauseInstanceOf(IllegalArgumentException.class) + .hasRootCauseMessage("No space character found in '1234.56'"); + + } + +} diff --git a/jackson/src/test/java/org/fuin/objects4j/jackson/CurrencyAmountJacksonSerializerTest.java b/jackson/src/test/java/org/fuin/objects4j/jackson/CurrencyAmountJacksonSerializerTest.java new file mode 100644 index 0000000..70414f1 --- /dev/null +++ b/jackson/src/test/java/org/fuin/objects4j/jackson/CurrencyAmountJacksonSerializerTest.java @@ -0,0 +1,43 @@ +/** + * Copyright (C) 2013 Future Invent Informationsmanagement GmbH. All rights + * reserved. + *

+ * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. + *

+ * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + *

+ * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see . + */ +package org.fuin.objects4j.jackson; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.fuin.objects4j.core.CurrencyAmount; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Test for the {@link CurrencyAmountJacksonSerializer} class. + */ +class CurrencyAmountJacksonSerializerTest { + + private static final String JSON = "{\"ca\":\"1234.56 EUR\"}"; + + @Test + void testSerializeJackson() throws JsonProcessingException { + + final Data data = new Data(); + data.currencyAmount = new CurrencyAmount("1234.56", "EUR"); + assertThat(JacksonHelper.toJson(data)).isEqualTo(JSON); + + } + +} diff --git a/jackson/src/test/java/org/fuin/objects4j/jackson/CurrencyJacksonDeserializerTest.java b/jackson/src/test/java/org/fuin/objects4j/jackson/CurrencyJacksonDeserializerTest.java new file mode 100644 index 0000000..2a0f935 --- /dev/null +++ b/jackson/src/test/java/org/fuin/objects4j/jackson/CurrencyJacksonDeserializerTest.java @@ -0,0 +1,54 @@ +/** + * Copyright (C) 2013 Future Invent Informationsmanagement GmbH. All rights + * reserved. + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see . + */ +package org.fuin.objects4j.jackson; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.Test; + +import java.util.Currency; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +/** + * Test for the {@link CurrencyJacksonDeserializer} class. + */ +class CurrencyJacksonDeserializerTest { + + private static final String JSON = "{\"c\":\"EUR\"}"; + + @Test + void testSerializeDeserializeJackson() throws JsonProcessingException { + + final Data data = JacksonHelper.fromJson(JSON, Data.class); + assertThat(data.currency).isEqualTo(Currency.getInstance("EUR")); + + } + + @Test + void testDeserializeErrorJackson() { + + final String invalidJsonData = "{\"c\":\"ABCD\"}"; + assertThatThrownBy(() -> JacksonHelper.fromJson(invalidJsonData, Data.class)) + .hasRootCauseInstanceOf(IllegalArgumentException.class) + .hasRootCauseMessage(null); + + } + +} diff --git a/jackson/src/test/java/org/fuin/objects4j/jackson/CurrencyJacksonSerializerTest.java b/jackson/src/test/java/org/fuin/objects4j/jackson/CurrencyJacksonSerializerTest.java new file mode 100644 index 0000000..5e1fee1 --- /dev/null +++ b/jackson/src/test/java/org/fuin/objects4j/jackson/CurrencyJacksonSerializerTest.java @@ -0,0 +1,44 @@ +/** + * Copyright (C) 2013 Future Invent Informationsmanagement GmbH. All rights + * reserved. + *

+ * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. + *

+ * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + *

+ * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see . + */ +package org.fuin.objects4j.jackson; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.Test; + +import java.util.Currency; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Test for the {@link CurrencyJacksonSerializer} class. + */ +class CurrencyJacksonSerializerTest { + + private static final String JSON = "{\"c\":\"EUR\"}"; + + @Test + void testSerializeJackson() throws JsonProcessingException { + + final Data data = new Data(); + data.currency = Currency.getInstance("EUR"); + assertThat(JacksonHelper.toJson(data)).isEqualTo(JSON); + + } + +} diff --git a/jackson/src/test/java/org/fuin/objects4j/jackson/Data.java b/jackson/src/test/java/org/fuin/objects4j/jackson/Data.java new file mode 100644 index 0000000..790b710 --- /dev/null +++ b/jackson/src/test/java/org/fuin/objects4j/jackson/Data.java @@ -0,0 +1,109 @@ +/** + * Copyright (C) 2013 Future Invent Informationsmanagement GmbH. All rights + * reserved. + *

+ * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. + *

+ * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + *

+ * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see . + */ +package org.fuin.objects4j.jackson; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.tngtech.archunit.junit.ArchIgnore; +import org.fuin.objects4j.core.CurrencyAmount; +import org.fuin.objects4j.core.DayOfTheWeek; +import org.fuin.objects4j.core.DayOpeningHours; +import org.fuin.objects4j.core.EmailAddress; +import org.fuin.objects4j.core.Hour; +import org.fuin.objects4j.core.HourRange; +import org.fuin.objects4j.core.HourRanges; +import org.fuin.objects4j.core.MultiDayOfTheWeek; +import org.fuin.objects4j.core.PasswordSha512; +import org.fuin.objects4j.core.UserName; +import org.fuin.objects4j.core.WeeklyOpeningHours; + +import java.util.Currency; +import java.util.Locale; +import java.util.UUID; + +/** + * JSON container used for tests. + */ +@ArchIgnore +public class Data { + + @JsonSerialize(using = EmailAddressJacksonSerializer.class) + @JsonDeserialize(using = EmailAddressJacksonDeserializer.class) + public EmailAddress email; + + @JsonSerialize(using = PasswordSha512JacksonSerializer.class) + @JsonDeserialize(using = PasswordSha512JacksonDeserializer.class) + public PasswordSha512 passwordSha512; + + @JsonSerialize(using = UserNameJacksonSerializer.class) + @JsonDeserialize(using = UserNameJacksonDeserializer.class) + public UserName userName; + + @JsonSerialize(using = UUIDJacksonSerializer.class) + @JsonDeserialize(using = UUIDJacksonDeserializer.class) + public UUID uuid; + + @JsonProperty("ca") + @JsonSerialize(using = CurrencyAmountJacksonSerializer.class) + @JsonDeserialize(using = CurrencyAmountJacksonDeserializer.class) + public CurrencyAmount currencyAmount; + + @JsonProperty("c") + @JsonSerialize(using = CurrencyJacksonSerializer.class) + @JsonDeserialize(using = CurrencyJacksonDeserializer.class) + public Currency currency; + + @JsonProperty("any-str") + @JsonSerialize(using = AnyStrJacksonSerializer.class) + @JsonDeserialize(using = AnyStrJacksonDeserializer.class) + public AnyStr anyStr; + + @JsonSerialize(using = HourJacksonSerializer.class) + @JsonDeserialize(using = HourJacksonDeserializer.class) + public Hour hour; + + @JsonSerialize(using = HourRangeJacksonSerializer.class) + @JsonDeserialize(using = HourRangeJacksonDeserializer.class) + public HourRange hourRange; + + @JsonSerialize(using = HourRangesJacksonSerializer.class) + @JsonDeserialize(using = HourRangesJacksonDeserializer.class) + public HourRanges hourRanges; + + @JsonSerialize(using = DayOfTheWeekJacksonSerializer.class) + @JsonDeserialize(using = DayOfTheWeekJacksonDeserializer.class) + public DayOfTheWeek dayOfTheWeek; + + @JsonSerialize(using = MultiDayOfTheWeekJacksonSerializer.class) + @JsonDeserialize(using = MultiDayOfTheWeekJacksonDeserializer.class) + public MultiDayOfTheWeek multiDayOfTheWeek; + + @JsonSerialize(using = DayOpeningHoursJacksonSerializer.class) + @JsonDeserialize(using = DayOpeningHoursJacksonDeserializer.class) + public DayOpeningHours dayOpeningHours; + + @JsonSerialize(using = WeeklyOpeningHoursJacksonSerializer.class) + @JsonDeserialize(using = WeeklyOpeningHoursJacksonDeserializer.class) + public WeeklyOpeningHours weeklyOpeningHours; + + @JsonSerialize(using = LocaleJacksonSerializer.class) + @JsonDeserialize(using = LocaleJacksonDeserializer.class) + public Locale locale; + +} diff --git a/jackson/src/test/java/org/fuin/objects4j/jackson/DayOfTheWeekJacksonDeserializerTest.java b/jackson/src/test/java/org/fuin/objects4j/jackson/DayOfTheWeekJacksonDeserializerTest.java new file mode 100644 index 0000000..032e56e --- /dev/null +++ b/jackson/src/test/java/org/fuin/objects4j/jackson/DayOfTheWeekJacksonDeserializerTest.java @@ -0,0 +1,52 @@ +/** + * Copyright (C) 2013 Future Invent Informationsmanagement GmbH. All rights + * reserved. + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see . + */ +package org.fuin.objects4j.jackson; + +import com.fasterxml.jackson.core.JsonProcessingException; +import org.fuin.objects4j.core.DayOfTheWeek; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + + +/** + * Test for the {@link DayOfTheWeekJacksonDeserializer} class. + */ +public class DayOfTheWeekJacksonDeserializerTest { + + private static final String JSON = "{\"dayOfTheWeek\":\"FRI\"}"; + + @Test + public final void testMarshalUnmarshal() throws JsonProcessingException { + + final Data data = JacksonHelper.fromJson(JSON, Data.class); + assertThat(data.dayOfTheWeek).isEqualTo(DayOfTheWeek.FRI); + + } + + @Test + public final void testUnmarshalError() { + + final String invalidJsonData = "{\"dayOfTheWeek\":\"Monday\"}"; + assertThatThrownBy(() -> JacksonHelper.fromJson(invalidJsonData, Data.class)) + .hasRootCauseInstanceOf(IllegalArgumentException.class) + .hasRootCauseMessage("Unknown day of week: 'Monday'"); + + } +} diff --git a/jackson/src/test/java/org/fuin/objects4j/jackson/DayOfTheWeekJacksonSerializerTest.java b/jackson/src/test/java/org/fuin/objects4j/jackson/DayOfTheWeekJacksonSerializerTest.java new file mode 100644 index 0000000..f4c85ec --- /dev/null +++ b/jackson/src/test/java/org/fuin/objects4j/jackson/DayOfTheWeekJacksonSerializerTest.java @@ -0,0 +1,43 @@ +/** + * Copyright (C) 2013 Future Invent Informationsmanagement GmbH. All rights + * reserved. + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see . + */ +package org.fuin.objects4j.jackson; + +import com.fasterxml.jackson.core.JsonProcessingException; +import org.fuin.objects4j.core.DayOfTheWeek; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + + +/** + * Test for the {@link DayOfTheWeekJacksonSerializer} class. + */ +public class DayOfTheWeekJacksonSerializerTest { + + private static final String JSON = "{\"dayOfTheWeek\":\"FRI\"}"; + + @Test + public final void testMarshal() throws JsonProcessingException { + + final Data data = new Data(); + data.dayOfTheWeek = DayOfTheWeek.FRI; + assertThat(JacksonHelper.toJson(data)).isEqualTo(JSON); + + } + +} diff --git a/jackson/src/test/java/org/fuin/objects4j/jackson/DayOpeningHoursJacksonDeserializerTest.java b/jackson/src/test/java/org/fuin/objects4j/jackson/DayOpeningHoursJacksonDeserializerTest.java new file mode 100644 index 0000000..e29d75d --- /dev/null +++ b/jackson/src/test/java/org/fuin/objects4j/jackson/DayOpeningHoursJacksonDeserializerTest.java @@ -0,0 +1,53 @@ +/** + * Copyright (C) 2013 Future Invent Informationsmanagement GmbH. All rights + * reserved. + *

+ * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. + *

+ * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + *

+ * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see . + */ +package org.fuin.objects4j.jackson; + +import com.fasterxml.jackson.core.JsonProcessingException; +import org.fuin.objects4j.common.ConstraintViolationException; +import org.fuin.objects4j.core.DayOpeningHours; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +/** + * Test for the {@link DayOpeningHoursJacksonDeserializer} class. + */ +public class DayOpeningHoursJacksonDeserializerTest { + + private static final String JSON = "{\"dayOpeningHours\":\"MON 00:00-24:00\"}"; + + @Test + public final void testMarshalUnmarshal() throws JsonProcessingException { + + final Data data = JacksonHelper.fromJson(JSON, Data.class); + assertThat(data.dayOpeningHours).isEqualTo(new DayOpeningHours("MON 00:00-24:00")); + + } + + @Test + public final void testUnmarshalError() { + + final String invalidJsonData = "{\"dayOpeningHours\":\"17-18\"}"; + assertThatThrownBy(() -> JacksonHelper.fromJson(invalidJsonData, Data.class)) + .hasRootCauseInstanceOf(ConstraintViolationException.class) + .hasRootCauseMessage("The argument 'dayOpeningHours' does not represent a valid hour range like 'Mon 09:00-12:00+13:00-17:00': '17-18'"); + + } + +} diff --git a/jackson/src/test/java/org/fuin/objects4j/jackson/DayOpeningHoursJacksonSerializerTest.java b/jackson/src/test/java/org/fuin/objects4j/jackson/DayOpeningHoursJacksonSerializerTest.java new file mode 100644 index 0000000..05ce03c --- /dev/null +++ b/jackson/src/test/java/org/fuin/objects4j/jackson/DayOpeningHoursJacksonSerializerTest.java @@ -0,0 +1,44 @@ +/** + * Copyright (C) 2013 Future Invent Informationsmanagement GmbH. All rights + * reserved. + *

+ * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. + *

+ * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + *

+ * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see . + */ +package org.fuin.objects4j.jackson; + +import com.fasterxml.jackson.core.JsonProcessingException; +import org.fuin.objects4j.common.ConstraintViolationException; +import org.fuin.objects4j.core.DayOpeningHours; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +/** + * Test for the {@link DayOpeningHoursJacksonSerializer} class. + */ +public class DayOpeningHoursJacksonSerializerTest { + + private static final String JSON = "{\"dayOpeningHours\":\"MON 00:00-24:00\"}"; + + @Test + public final void testMarshal() throws JsonProcessingException { + + final Data data = new Data(); + data.dayOpeningHours = new DayOpeningHours("MON 00:00-24:00"); + assertThat(JacksonHelper.toJson(data)).isEqualTo(JSON); + + } + +} diff --git a/jackson/src/test/java/org/fuin/objects4j/jackson/EmailAddressJacksonDeserializerTest.java b/jackson/src/test/java/org/fuin/objects4j/jackson/EmailAddressJacksonDeserializerTest.java new file mode 100644 index 0000000..00f826b --- /dev/null +++ b/jackson/src/test/java/org/fuin/objects4j/jackson/EmailAddressJacksonDeserializerTest.java @@ -0,0 +1,52 @@ +/** + * Copyright (C) 2013 Future Invent Informationsmanagement GmbH. All rights + * reserved. + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see . + */ +package org.fuin.objects4j.jackson; + +import com.fasterxml.jackson.core.JsonProcessingException; +import org.fuin.objects4j.common.ConstraintViolationException; +import org.fuin.objects4j.core.EmailAddress; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +/** + * Test for the {@link EmailAddressJacksonDeserializer} class. + */ +public class EmailAddressJacksonDeserializerTest { + + private static final String JSON = "{\"email\":\"a@b.c\"}"; + + @Test + public final void testMarshalUnmarshal() throws JsonProcessingException { + + final Data data = JacksonHelper.fromJson(JSON, Data.class); + assertThat(data.email).isEqualTo(new EmailAddress("a@b.c")); + + } + + @Test + public final void testUnmarshalError() { + + final String invalidJsonData = "{\"email\":\"abc@\"}"; + assertThatThrownBy(() -> JacksonHelper.fromJson(invalidJsonData, Data.class)) + .hasRootCauseInstanceOf(ConstraintViolationException.class) + .hasRootCauseMessage("The argument 'emailAddress' is not valid: 'abc@'"); + + } +} diff --git a/jackson/src/test/java/org/fuin/objects4j/jackson/EmailAddressJacksonSerializerTest.java b/jackson/src/test/java/org/fuin/objects4j/jackson/EmailAddressJacksonSerializerTest.java new file mode 100644 index 0000000..77b5639 --- /dev/null +++ b/jackson/src/test/java/org/fuin/objects4j/jackson/EmailAddressJacksonSerializerTest.java @@ -0,0 +1,42 @@ +/** + * Copyright (C) 2013 Future Invent Informationsmanagement GmbH. All rights + * reserved. + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see . + */ +package org.fuin.objects4j.jackson; + +import com.fasterxml.jackson.core.JsonProcessingException; +import org.fuin.objects4j.core.EmailAddress; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Test for the {@link EmailAddressJacksonSerializer} class. + */ +public class EmailAddressJacksonSerializerTest { + + private static final String JSON = "{\"email\":\"a@b.c\"}"; + + @Test + public final void testMarshal() throws JsonProcessingException { + + final Data data = new Data(); + data.email = new EmailAddress("a@b.c"); + assertThat(JacksonHelper.toJson(data)).isEqualTo(JSON); + + } + +} diff --git a/jackson/src/test/java/org/fuin/objects4j/jackson/HourJacksonDeserializerTest.java b/jackson/src/test/java/org/fuin/objects4j/jackson/HourJacksonDeserializerTest.java new file mode 100644 index 0000000..c0503bc --- /dev/null +++ b/jackson/src/test/java/org/fuin/objects4j/jackson/HourJacksonDeserializerTest.java @@ -0,0 +1,52 @@ +/** + * Copyright (C) 2013 Future Invent Informationsmanagement GmbH. All rights + * reserved. + *

+ * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. + *

+ * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + *

+ * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see . + */ +package org.fuin.objects4j.jackson; + +import com.fasterxml.jackson.core.JsonProcessingException; +import org.fuin.objects4j.common.ConstraintViolationException; +import org.fuin.objects4j.core.Hour; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +/** + * Test for the {@link HourJacksonDeserializer} class. + */ +public class HourJacksonDeserializerTest { + + private static final String JSON = "{\"hour\":\"23:59\"}"; + + @Test + public final void testMarshalUnmarshal() throws JsonProcessingException { + + final Data data = JacksonHelper.fromJson(JSON, Data.class); + assertThat(data.hour).isEqualTo(new Hour("23:59")); + + } + + @Test + public final void testUnmarshalError() { + + final String invalidJsonData = "{\"hour\":\"23:\"}"; + assertThatThrownBy(() -> JacksonHelper.fromJson(invalidJsonData, Data.class)) + .hasRootCauseInstanceOf(ConstraintViolationException.class) + .hasRootCauseMessage("The argument 'hour' does not represent a valid hour like '00:00' or '23:59' or '24:00': '23:'"); + + } +} diff --git a/jackson/src/test/java/org/fuin/objects4j/jackson/HourJacksonSerializerTest.java b/jackson/src/test/java/org/fuin/objects4j/jackson/HourJacksonSerializerTest.java new file mode 100644 index 0000000..96af327 --- /dev/null +++ b/jackson/src/test/java/org/fuin/objects4j/jackson/HourJacksonSerializerTest.java @@ -0,0 +1,42 @@ +/** + * Copyright (C) 2013 Future Invent Informationsmanagement GmbH. All rights + * reserved. + *

+ * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. + *

+ * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + *

+ * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see . + */ +package org.fuin.objects4j.jackson; + +import com.fasterxml.jackson.core.JsonProcessingException; +import org.fuin.objects4j.core.Hour; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Test for the {@link HourJacksonSerializer} class. + */ +public class HourJacksonSerializerTest { + + private static final String JSON = "{\"hour\":\"23:59\"}"; + + @Test + public final void testMarshal() throws JsonProcessingException { + + final Data data = new Data(); + data.hour = new Hour("23:59"); + assertThat(JacksonHelper.toJson(data)).isEqualTo(JSON); + + } + +} diff --git a/jackson/src/test/java/org/fuin/objects4j/jackson/HourRangeJacksonDeserializerTest.java b/jackson/src/test/java/org/fuin/objects4j/jackson/HourRangeJacksonDeserializerTest.java new file mode 100644 index 0000000..cf90927 --- /dev/null +++ b/jackson/src/test/java/org/fuin/objects4j/jackson/HourRangeJacksonDeserializerTest.java @@ -0,0 +1,52 @@ +/** + * Copyright (C) 2013 Future Invent Informationsmanagement GmbH. All rights + * reserved. + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see . + */ +package org.fuin.objects4j.jackson; + +import com.fasterxml.jackson.core.JsonProcessingException; +import org.fuin.objects4j.common.ConstraintViolationException; +import org.fuin.objects4j.core.HourRange; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +/** + * Test for the {@link HourRangeJacksonDeserializer} class. + */ +public class HourRangeJacksonDeserializerTest { + + private static final String JSON = "{\"hourRange\":\"00:00-24:00\"}"; + + @Test + public final void testMarshalUnmarshal() throws JsonProcessingException { + + final Data data = JacksonHelper.fromJson(JSON, Data.class); + assertThat(data.hourRange).isEqualTo(new HourRange("00:00-24:00")); + + } + + @Test + public final void testUnmarshalError() { + + final String invalidJsonData = "{\"hourRange\":\"17-18\"}"; + assertThatThrownBy(() -> JacksonHelper.fromJson(invalidJsonData, Data.class)) + .hasRootCauseInstanceOf(ConstraintViolationException.class) + .hasRootCauseMessage("The argument 'hourRange' does not represent a valid hour range like '00:00-24:00' or '06:00-21:00': '17-18'"); + + } +} diff --git a/jackson/src/test/java/org/fuin/objects4j/jackson/HourRangeJacksonSerializerTest.java b/jackson/src/test/java/org/fuin/objects4j/jackson/HourRangeJacksonSerializerTest.java new file mode 100644 index 0000000..c1f48af --- /dev/null +++ b/jackson/src/test/java/org/fuin/objects4j/jackson/HourRangeJacksonSerializerTest.java @@ -0,0 +1,42 @@ +/** + * Copyright (C) 2013 Future Invent Informationsmanagement GmbH. All rights + * reserved. + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see . + */ +package org.fuin.objects4j.jackson; + +import com.fasterxml.jackson.core.JsonProcessingException; +import org.fuin.objects4j.core.HourRange; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Test for the {@link HourRangeJacksonSerializer} class. + */ +public class HourRangeJacksonSerializerTest { + + private static final String JSON = "{\"hourRange\":\"00:00-24:00\"}"; + + @Test + public final void testMarshal() throws JsonProcessingException { + + final Data data = new Data(); + data.hourRange = new HourRange("00:00-24:00"); + assertThat(JacksonHelper.toJson(data)).isEqualTo(JSON); + + } + +} diff --git a/jackson/src/test/java/org/fuin/objects4j/jackson/HourRangesJacksonDeserializerTest.java b/jackson/src/test/java/org/fuin/objects4j/jackson/HourRangesJacksonDeserializerTest.java new file mode 100644 index 0000000..b64bd0d --- /dev/null +++ b/jackson/src/test/java/org/fuin/objects4j/jackson/HourRangesJacksonDeserializerTest.java @@ -0,0 +1,53 @@ +/** + * Copyright (C) 2013 Future Invent Informationsmanagement GmbH. All rights + * reserved. + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see . + */ +package org.fuin.objects4j.jackson; + +import com.fasterxml.jackson.core.JsonProcessingException; +import org.fuin.objects4j.common.ConstraintViolationException; +import org.fuin.objects4j.core.HourRanges; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; + +/** + * Test for the {@link HourRangesJacksonDeserializer} class. + */ +public class HourRangesJacksonDeserializerTest { + + private static final String JSON = "{\"hourRanges\":\"09:00-12:00+13:00-17:00\"}"; + + @Test + public final void testMarshalUnmarshal() throws JsonProcessingException { + + final Data data = JacksonHelper.fromJson(JSON, Data.class); + assertThat(data.hourRanges).isEqualTo(new HourRanges("09:00-12:00+13:00-17:00")); + + } + + @Test + public final void testUnmarshalError() { + + final String invalidJsonData = "{\"hourRanges\":\"17-18+19-20\"}"; + assertThatThrownBy(() -> JacksonHelper.fromJson(invalidJsonData, Data.class)) + .hasRootCauseInstanceOf(ConstraintViolationException.class) + .hasRootCauseMessage("The argument 'ranges' does not represent a valid hour range like '09:00-12:00+13:00-17:00': '17-18+19-20'"); + + } + +} diff --git a/jackson/src/test/java/org/fuin/objects4j/jackson/HourRangesJacksonSerializerTest.java b/jackson/src/test/java/org/fuin/objects4j/jackson/HourRangesJacksonSerializerTest.java new file mode 100644 index 0000000..b4ee8cd --- /dev/null +++ b/jackson/src/test/java/org/fuin/objects4j/jackson/HourRangesJacksonSerializerTest.java @@ -0,0 +1,44 @@ +/** + * Copyright (C) 2013 Future Invent Informationsmanagement GmbH. All rights + * reserved. + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see . + */ +package org.fuin.objects4j.jackson; + +import com.fasterxml.jackson.core.JsonProcessingException; +import org.fuin.objects4j.common.ConstraintViolationException; +import org.fuin.objects4j.core.HourRanges; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; + +/** + * Test for the {@link HourRangesJacksonSerializer} class. + */ +public class HourRangesJacksonSerializerTest { + + private static final String JSON = "{\"hourRanges\":\"09:00-12:00+13:00-17:00\"}"; + + @Test + public final void testMarshal() throws JsonProcessingException { + + final Data data = new Data(); + data.hourRanges = new HourRanges("09:00-12:00+13:00-17:00"); + assertThat(JacksonHelper.toJson(data)).isEqualTo(JSON); + + } + +} diff --git a/jackson/src/test/java/org/fuin/objects4j/jackson/JacksonHelper.java b/jackson/src/test/java/org/fuin/objects4j/jackson/JacksonHelper.java new file mode 100644 index 0000000..44f3375 --- /dev/null +++ b/jackson/src/test/java/org/fuin/objects4j/jackson/JacksonHelper.java @@ -0,0 +1,67 @@ +/** + * Copyright (C) 2013 Future Invent Informationsmanagement GmbH. All rights + * reserved. + *

+ * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. + *

+ * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + *

+ * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see . + */ +package org.fuin.objects4j.jackson; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.tngtech.archunit.junit.ArchIgnore; + +/** + * Utility class for this package. + */ +@ArchIgnore +class JacksonHelper { + + private JacksonHelper() { + throw new UnsupportedOperationException("Instances of utility classes are not allowed"); + } + + /** + * Converts an object to JSON. + * + * @param obj Object to serialize. + * @return JSON. + */ + public static String toJson(final T obj) { + try { + final ObjectMapper mapper = new ObjectMapper(); + mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); + return mapper.writeValueAsString(obj); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + } + + /** + * Converts JSON to an object. + * + * @param json JSON. + * @param clasz Class of the expected instance. + * @return New instance created using JSON input. + */ + public static T fromJson(final String json, final Class clasz) { + try { + final ObjectMapper mapper = new ObjectMapper(); + return mapper.readValue(json, clasz); + } catch (final JsonProcessingException ex) { + throw new RuntimeException(ex); + } + } + +} \ No newline at end of file diff --git a/jackson/src/test/java/org/fuin/objects4j/jackson/LocaleJacksonDeserializerTest.java b/jackson/src/test/java/org/fuin/objects4j/jackson/LocaleJacksonDeserializerTest.java new file mode 100644 index 0000000..ef87043 --- /dev/null +++ b/jackson/src/test/java/org/fuin/objects4j/jackson/LocaleJacksonDeserializerTest.java @@ -0,0 +1,57 @@ +/** + * Copyright (C) 2013 Future Invent Informationsmanagement GmbH. All rights + * reserved. + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see . + */ +package org.fuin.objects4j.jackson; + +import com.fasterxml.jackson.core.JsonProcessingException; +import org.junit.jupiter.api.Test; + +import java.util.Locale; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; + +/** + * Test for the {@link LocaleJacksonDeserializer} class. + */ +public class LocaleJacksonDeserializerTest { + + private static final String LOCALE_STR = "en_US_NY"; + + private static final Locale LOCALE = new Locale("en", "US", "NY"); + + private static final String JSON = "{\"locale\":\"" +LOCALE_STR + "\"}"; + + @Test + public final void testMarshalUnmarshal() throws JsonProcessingException { + + final Data data = JacksonHelper.fromJson(JSON, Data.class); + assertThat(data.locale).isEqualTo(LOCALE); + + } + + @Test + public final void testUnmarshalError() { + + final String invalidJsonData = "{\"locale\":\"\"}"; + assertThatThrownBy(() -> JacksonHelper.fromJson(invalidJsonData, Data.class)) + .hasRootCauseInstanceOf(IllegalArgumentException.class) + .hasRootCauseMessage("Cannot convert: ''"); + + } + +} diff --git a/jackson/src/test/java/org/fuin/objects4j/jackson/LocaleJacksonSerializerTest.java b/jackson/src/test/java/org/fuin/objects4j/jackson/LocaleJacksonSerializerTest.java new file mode 100644 index 0000000..ff13756 --- /dev/null +++ b/jackson/src/test/java/org/fuin/objects4j/jackson/LocaleJacksonSerializerTest.java @@ -0,0 +1,49 @@ +/** + * Copyright (C) 2013 Future Invent Informationsmanagement GmbH. All rights + * reserved. + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see . + */ +package org.fuin.objects4j.jackson; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.Test; + +import java.util.Locale; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; + +/** + * Test for the {@link LocaleJacksonSerializer} class. + */ +public class LocaleJacksonSerializerTest { + + private static final String LOCALE_STR = "en_US_NY"; + + private static final Locale LOCALE = new Locale("en", "US", "NY"); + + private static final String JSON = "{\"locale\":\"" +LOCALE_STR + "\"}"; + + @Test + public final void testMarshal() throws JsonProcessingException { + + final Data data = new Data(); + data.locale = LOCALE; + assertThat(JacksonHelper.toJson(data)).isEqualTo(JSON); + + } + +} diff --git a/jackson/src/test/java/org/fuin/objects4j/jackson/MultiDayOfTheWeekJacksonDeserializerTest.java b/jackson/src/test/java/org/fuin/objects4j/jackson/MultiDayOfTheWeekJacksonDeserializerTest.java new file mode 100644 index 0000000..44bf8f3 --- /dev/null +++ b/jackson/src/test/java/org/fuin/objects4j/jackson/MultiDayOfTheWeekJacksonDeserializerTest.java @@ -0,0 +1,53 @@ +/** + * Copyright (C) 2013 Future Invent Informationsmanagement GmbH. All rights + * reserved. + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see . + */ +package org.fuin.objects4j.jackson; + +import com.fasterxml.jackson.core.JsonProcessingException; +import org.fuin.objects4j.common.ConstraintViolationException; +import org.fuin.objects4j.core.MultiDayOfTheWeek; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; + +/** + * Test for the {@link MultiDayOfTheWeekJacksonDeserializer} class. + */ +public class MultiDayOfTheWeekJacksonDeserializerTest { + + private static final String JSON = "{\"multiDayOfTheWeek\":\"MON/TUE\"}"; + + @Test + public final void testMarshalUnmarshal() throws JsonProcessingException { + + final Data data = JacksonHelper.fromJson(JSON, Data.class); + assertThat(data.multiDayOfTheWeek).isEqualTo(new MultiDayOfTheWeek("Mon/Tue")); + + } + + @Test + public final void testUnmarshalError() { + + final String invalidJsonData = "{\"multiDayOfTheWeek\":\"Mon+Tue\"}"; + assertThatThrownBy(() -> JacksonHelper.fromJson(invalidJsonData, Data.class)) + .hasRootCauseInstanceOf(ConstraintViolationException.class) + .hasRootCauseMessage("The argument 'multipleDayOfTheWeek' does not represent valid days of the week like 'Mon/Tue/Wed-Fri': 'Mon+Tue'"); + + } + +} diff --git a/jackson/src/test/java/org/fuin/objects4j/jackson/MultiDayOfTheWeekJacksonSerializerTest.java b/jackson/src/test/java/org/fuin/objects4j/jackson/MultiDayOfTheWeekJacksonSerializerTest.java new file mode 100644 index 0000000..03f4c16 --- /dev/null +++ b/jackson/src/test/java/org/fuin/objects4j/jackson/MultiDayOfTheWeekJacksonSerializerTest.java @@ -0,0 +1,42 @@ +/** + * Copyright (C) 2013 Future Invent Informationsmanagement GmbH. All rights + * reserved. + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see . + */ +package org.fuin.objects4j.jackson; + +import com.fasterxml.jackson.core.JsonProcessingException; +import org.fuin.objects4j.core.MultiDayOfTheWeek; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; + +/** + * Test for the {@link MultiDayOfTheWeekJacksonSerializer} class. + */ +public class MultiDayOfTheWeekJacksonSerializerTest { + + private static final String JSON = "{\"multiDayOfTheWeek\":\"MON/TUE\"}"; + + @Test + public final void testMarshal() throws JsonProcessingException { + + final Data data = new Data(); + data.multiDayOfTheWeek = new MultiDayOfTheWeek("Mon/Tue"); + assertThat(JacksonHelper.toJson(data)).isEqualTo(JSON); + + } + +} diff --git a/jackson/src/test/java/org/fuin/objects4j/jackson/Objects4JJacksonAdapterModuleTest.java b/jackson/src/test/java/org/fuin/objects4j/jackson/Objects4JJacksonAdapterModuleTest.java new file mode 100644 index 0000000..4364cf1 --- /dev/null +++ b/jackson/src/test/java/org/fuin/objects4j/jackson/Objects4JJacksonAdapterModuleTest.java @@ -0,0 +1,10 @@ +package org.fuin.objects4j.jackson; + +/** + * Test for the {@link Objects4JJacksonAdapterModule} class. + */ +class Objects4JJacksonAdapterModuleTest { + + // Nothing to test yet + +} diff --git a/jaxb/src/test/java/org/fuin/objects4j/jaxb/PasswordXmlAdapterTest.java b/jackson/src/test/java/org/fuin/objects4j/jackson/PasswordSha512JacksonDeserializerTest.java similarity index 53% rename from jaxb/src/test/java/org/fuin/objects4j/jaxb/PasswordXmlAdapterTest.java rename to jackson/src/test/java/org/fuin/objects4j/jackson/PasswordSha512JacksonDeserializerTest.java index fec0887..577495b 100644 --- a/jaxb/src/test/java/org/fuin/objects4j/jaxb/PasswordXmlAdapterTest.java +++ b/jackson/src/test/java/org/fuin/objects4j/jackson/PasswordSha512JacksonDeserializerTest.java @@ -15,47 +15,40 @@ * You should have received a copy of the GNU Lesser General Public License * along with this library. If not, see . */ -package org.fuin.objects4j.jaxb; +package org.fuin.objects4j.jackson; -import jakarta.xml.bind.JAXBException; +import com.fasterxml.jackson.core.JsonProcessingException; import org.fuin.objects4j.common.ConstraintViolationException; -import org.fuin.objects4j.core.Password; +import org.fuin.objects4j.core.PasswordSha512; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.fuin.utils4j.jaxb.JaxbUtils.XML_PREFIX; -public class PasswordXmlAdapterTest { - - private static final String XML = XML_PREFIX + ""; - - @Test - public final void testMarshal() throws JAXBException { +/** + * Test for the {@link PasswordSha512JacksonDeserializer} class. + */ +public class PasswordSha512JacksonDeserializerTest { - final Data data = new Data(); - data.password = new Password("abcd1234"); - assertThat(JaxbHelper.marshalData(data)).isEqualTo(XML); + private static final String HASH = "925f43c3cfb956bbe3c6aa8023ba7ad5cfa21d104186fffc69e768e55940d9653b1cd36fba614fba2e1844f4436da20f83750c6ec1db356da154691bdd71a9b1"; - } + private static final String JSON = "{\"passwordSha512\":\"" + HASH + "\"}"; @Test - public final void testMarshalUnmarshal() throws JAXBException { + public final void testMarshalUnmarshal() throws JsonProcessingException { - final Data data = JaxbHelper.unmarshalData(XML); - assertThat(data.password).isNotNull(); - assertThat(data.password).isEqualTo(new Password("abcd1234")); + final Data data = JacksonHelper.fromJson(JSON, Data.class); + assertThat(data.passwordSha512).isEqualTo(new PasswordSha512(HASH)); } @Test public final void testUnmarshalError() { - final String invalidXmlData = XML_PREFIX + ""; - assertThatThrownBy(() -> JaxbHelper.unmarshalData(invalidXmlData)) + final String invalidJsonData = "{\"passwordSha512\":\"1\"}"; + assertThatThrownBy(() -> JacksonHelper.fromJson(invalidJsonData, Data.class)) .hasRootCauseInstanceOf(ConstraintViolationException.class) - .hasRootCauseMessage("The argument 'password' is not valid: 'abcd123'"); + .hasRootCauseMessage("The argument 'hexEncodedHash' is not valid"); } - } diff --git a/jackson/src/test/java/org/fuin/objects4j/jackson/PasswordSha512JacksonSerializerTest.java b/jackson/src/test/java/org/fuin/objects4j/jackson/PasswordSha512JacksonSerializerTest.java new file mode 100644 index 0000000..7bf68be --- /dev/null +++ b/jackson/src/test/java/org/fuin/objects4j/jackson/PasswordSha512JacksonSerializerTest.java @@ -0,0 +1,46 @@ +/** + * Copyright (C) 2013 Future Invent Informationsmanagement GmbH. All rights + * reserved. + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see . + */ +package org.fuin.objects4j.jackson; + +import com.fasterxml.jackson.core.JsonProcessingException; +import org.fuin.objects4j.common.ConstraintViolationException; +import org.fuin.objects4j.core.PasswordSha512; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +/** + * Test for the {@link PasswordSha512JacksonSerializer} class. + */ +public class PasswordSha512JacksonSerializerTest { + + private static final String HASH = "925f43c3cfb956bbe3c6aa8023ba7ad5cfa21d104186fffc69e768e55940d9653b1cd36fba614fba2e1844f4436da20f83750c6ec1db356da154691bdd71a9b1"; + + private static final String JSON = "{\"passwordSha512\":\"" + HASH + "\"}"; + + @Test + public final void testMarshal() throws JsonProcessingException { + + final Data data = new Data(); + data.passwordSha512 = new PasswordSha512(HASH); + assertThat(JacksonHelper.toJson(data)).isEqualTo(JSON); + + } + +} diff --git a/jackson/src/test/java/org/fuin/objects4j/jackson/UUIDJacksonDeserializerTest.java b/jackson/src/test/java/org/fuin/objects4j/jackson/UUIDJacksonDeserializerTest.java new file mode 100644 index 0000000..17649b1 --- /dev/null +++ b/jackson/src/test/java/org/fuin/objects4j/jackson/UUIDJacksonDeserializerTest.java @@ -0,0 +1,55 @@ +/** + * Copyright (C) 2013 Future Invent Informationsmanagement GmbH. All rights + * reserved. + *

+ * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. + *

+ * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + *

+ * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see . + */ +package org.fuin.objects4j.jackson; + +import com.fasterxml.jackson.core.JsonProcessingException; +import org.junit.jupiter.api.Test; + +import java.util.UUID; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +/** + * Test for the {@link UUIDJacksonDeserializer} class. + */ +public class UUIDJacksonDeserializerTest { + + private static final UUID ID = UUID.fromString("ec5468bd-9cd9-4a0f-a502-96190f6a0995"); + + private static final String JSON = "{\"uuid\":\"ec5468bd-9cd9-4a0f-a502-96190f6a0995\"}"; + + @Test + void testMarshalUnmarshalJsonb() throws JsonProcessingException { + + final Data data = JacksonHelper.fromJson(JSON, Data.class); + assertThat(data.uuid).isEqualTo(ID); + + } + + @Test + void testUnmarshalErrorJsonb() { + + final String invalidJsonData = "{\"uuid\":\"foo\"}"; + assertThatThrownBy(() -> JacksonHelper.fromJson(invalidJsonData, Data.class)) + .hasRootCauseInstanceOf(IllegalArgumentException.class) + .hasRootCauseMessage("Invalid UUID string: foo"); + + } + +} diff --git a/jackson/src/test/java/org/fuin/objects4j/jackson/UUIDJacksonSerializerTest.java b/jackson/src/test/java/org/fuin/objects4j/jackson/UUIDJacksonSerializerTest.java new file mode 100644 index 0000000..458e368 --- /dev/null +++ b/jackson/src/test/java/org/fuin/objects4j/jackson/UUIDJacksonSerializerTest.java @@ -0,0 +1,48 @@ +/** + * Copyright (C) 2013 Future Invent Informationsmanagement GmbH. All rights + * reserved. + *

+ * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. + *

+ * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + *

+ * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see . + */ +package org.fuin.objects4j.jackson; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.Test; + +import java.util.UUID; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +/** + * Test for the {@link UUIDJacksonSerializer} class. + */ +public class UUIDJacksonSerializerTest { + + private static final UUID ID = UUID.fromString("ec5468bd-9cd9-4a0f-a502-96190f6a0995"); + + private static final String JSON = "{\"uuid\":\"ec5468bd-9cd9-4a0f-a502-96190f6a0995\"}"; + + @Test + void testMarshalJsonb() throws JsonProcessingException { + + final Data data = new Data(); + data.uuid = ID; + assertThat(JacksonHelper.toJson(data)).isEqualTo(JSON); + + } + + +} diff --git a/jsonb/src/test/java/org/fuin/objects4j/jsonb/PasswordJsonbAdapterTest.java b/jackson/src/test/java/org/fuin/objects4j/jackson/UserNameJacksonDeserializerTest.java similarity index 53% rename from jsonb/src/test/java/org/fuin/objects4j/jsonb/PasswordJsonbAdapterTest.java rename to jackson/src/test/java/org/fuin/objects4j/jackson/UserNameJacksonDeserializerTest.java index cca8802..2ddd5b2 100644 --- a/jsonb/src/test/java/org/fuin/objects4j/jsonb/PasswordJsonbAdapterTest.java +++ b/jackson/src/test/java/org/fuin/objects4j/jackson/UserNameJacksonDeserializerTest.java @@ -15,48 +15,40 @@ * You should have received a copy of the GNU Lesser General Public License * along with this library. If not, see . */ -package org.fuin.objects4j.jsonb; +package org.fuin.objects4j.jackson; +import com.fasterxml.jackson.core.JsonProcessingException; import org.fuin.objects4j.common.ConstraintViolationException; -import org.fuin.objects4j.core.Password; +import org.fuin.objects4j.core.UserName; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.fuin.objects4j.jsonb.JsonbHelper.fromJson; -import static org.fuin.objects4j.jsonb.JsonbHelper.toJson; /** - * Test for the {@link PasswordJsonbAdapter} class. + * Test for the {@link UserNameJacksonDeserializer} class. */ -public class PasswordJsonbAdapterTest { +public class UserNameJacksonDeserializerTest { - private static final String JSON = "{\"password\":\"abcd1234\"}"; + private static final String USER_NAME = "michael-1_a"; - @Test - void testMarshalJsonb() { - - final Data data = new Data(); - data.password = new Password("abcd1234"); - assertThat(toJson(data)).isEqualTo(JSON); - - } + private static final String JSON = "{\"userName\":\"" + USER_NAME + "\"}"; @Test - void testMarshalUnmarshalJsonb() { + public final void testMarshalUnmarshal() throws JsonProcessingException { - final Data data = fromJson(JSON, Data.class); - assertThat(data.password).isEqualTo(new Password("abcd1234")); + final Data data = JacksonHelper.fromJson(JSON, Data.class); + assertThat(data.userName).isEqualTo(new UserName(USER_NAME)); } @Test - void testUnmarshalErrorJsonb() { + public final void testUnmarshalError() { - final String invalidJsonData = "{\"password\":\"abcd123\"}"; - assertThatThrownBy(() -> fromJson(invalidJsonData, Data.class)) + final String invalidJsonData = "{\"userName\":\"x\"}"; + assertThatThrownBy(() -> JacksonHelper.fromJson(invalidJsonData, Data.class)) .hasRootCauseInstanceOf(ConstraintViolationException.class) - .hasRootCauseMessage("The argument 'password' is not valid: 'abcd123'"); + .hasRootCauseMessage("The argument 'userName' is not valid: 'x'"); } diff --git a/jackson/src/test/java/org/fuin/objects4j/jackson/UserNameJacksonSerializerTest.java b/jackson/src/test/java/org/fuin/objects4j/jackson/UserNameJacksonSerializerTest.java new file mode 100644 index 0000000..2fea62d --- /dev/null +++ b/jackson/src/test/java/org/fuin/objects4j/jackson/UserNameJacksonSerializerTest.java @@ -0,0 +1,46 @@ +/** + * Copyright (C) 2013 Future Invent Informationsmanagement GmbH. All rights + * reserved. + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see . + */ +package org.fuin.objects4j.jackson; + +import com.fasterxml.jackson.core.JsonProcessingException; +import org.fuin.objects4j.common.ConstraintViolationException; +import org.fuin.objects4j.core.UserName; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +/** + * Test for the {@link UserNameJacksonSerializer} class. + */ +public class UserNameJacksonSerializerTest { + + private static final String USER_NAME = "michael-1_a"; + + private static final String JSON = "{\"userName\":\"" + USER_NAME + "\"}"; + + @Test + public final void testMarshal() throws JsonProcessingException { + + final Data data = new Data(); + data.userName = new UserName(USER_NAME); + assertThat(JacksonHelper.toJson(data)).isEqualTo(JSON); + + } + +} diff --git a/jackson/src/test/java/org/fuin/objects4j/jackson/ValueObjectStringJacksonDeserializerTest.java b/jackson/src/test/java/org/fuin/objects4j/jackson/ValueObjectStringJacksonDeserializerTest.java new file mode 100644 index 0000000..9c1c675 --- /dev/null +++ b/jackson/src/test/java/org/fuin/objects4j/jackson/ValueObjectStringJacksonDeserializerTest.java @@ -0,0 +1,41 @@ +/** + * Copyright (C) 2013 Future Invent Informationsmanagement GmbH. All rights + * reserved. + *

+ * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. + *

+ * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + *

+ * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see . + */ +package org.fuin.objects4j.jackson; + +import com.fasterxml.jackson.core.JsonProcessingException; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Test for the {@link ValueObjectStringJacksonDeserializer} class. + */ +public class ValueObjectStringJacksonDeserializerTest { + + private static final String JSON = "{\"any-str\":\"abcd1234\"}"; + + @Test + public final void testMarshalUnmarshal() throws JsonProcessingException { + + final Data data = JacksonHelper.fromJson(JSON, Data.class); + assertThat(data.anyStr).isNotNull(); + assertThat(data.anyStr).isEqualTo(new AnyStr("abcd1234")); + + } + +} diff --git a/jackson/src/test/java/org/fuin/objects4j/jackson/ValueObjectStringJacksonSerializerTest.java b/jackson/src/test/java/org/fuin/objects4j/jackson/ValueObjectStringJacksonSerializerTest.java new file mode 100644 index 0000000..c926283 --- /dev/null +++ b/jackson/src/test/java/org/fuin/objects4j/jackson/ValueObjectStringJacksonSerializerTest.java @@ -0,0 +1,42 @@ +/** + * Copyright (C) 2013 Future Invent Informationsmanagement GmbH. All rights + * reserved. + *

+ * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. + *

+ * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + *

+ * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see . + */ +package org.fuin.objects4j.jackson; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Test for the {@link ValueObjectStringJacksonSerializer} class. + */ +public class ValueObjectStringJacksonSerializerTest { + + private static final String JSON = "{\"any-str\":\"abcd1234\"}"; + + @Test + public final void testMarshal() throws JsonProcessingException { + + final Data data = new Data(); + data.anyStr = new AnyStr("abcd1234"); + assertThat(JacksonHelper.toJson(data)).isEqualTo(JSON); + + } + +} diff --git a/jackson/src/test/java/org/fuin/objects4j/jackson/WeeklyOpeningHoursJacksonDeserializerTest.java b/jackson/src/test/java/org/fuin/objects4j/jackson/WeeklyOpeningHoursJacksonDeserializerTest.java new file mode 100644 index 0000000..cd0acce --- /dev/null +++ b/jackson/src/test/java/org/fuin/objects4j/jackson/WeeklyOpeningHoursJacksonDeserializerTest.java @@ -0,0 +1,55 @@ +/** + * Copyright (C) 2013 Future Invent Informationsmanagement GmbH. All rights + * reserved. + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see . + */ +package org.fuin.objects4j.jackson; + +import com.fasterxml.jackson.core.JsonProcessingException; +import org.fuin.objects4j.common.ConstraintViolationException; +import org.fuin.objects4j.core.WeeklyOpeningHours; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; + +/** + * Test for the {@link WeeklyOpeningHoursJacksonDeserializer} class. + */ +public class WeeklyOpeningHoursJacksonDeserializerTest { + + private static final String HOURS = "MON-FRI 06:00-18:00,SAT/SUN 06:00-12:00"; + + private static final String JSON = "{\"weeklyOpeningHours\":\"" + HOURS + "\"}"; + + @Test + public final void testMarshalUnmarshal() throws JsonProcessingException { + + final Data data = JacksonHelper.fromJson(JSON, Data.class); + assertThat(data.weeklyOpeningHours).isEqualTo(new WeeklyOpeningHours(HOURS)); + + } + + @Test + public final void testUnmarshalError() { + + final String invalidJsonData = "{\"weeklyOpeningHours\":\"17-18+19-20\"}"; + assertThatThrownBy(() -> JacksonHelper.fromJson(invalidJsonData, Data.class)) + .hasRootCauseInstanceOf(ConstraintViolationException.class) + .hasRootCauseMessage("The argument 'weeklyOpeningHours' does not represent valid weekly opening hours like 'Mon-Fri 09:00-12:00+13:00-17:00,Sat/Sun 09:-12:00': '17-18+19-20'"); + + } + +} diff --git a/jackson/src/test/java/org/fuin/objects4j/jackson/WeeklyOpeningHoursJacksonSerializerTest.java b/jackson/src/test/java/org/fuin/objects4j/jackson/WeeklyOpeningHoursJacksonSerializerTest.java new file mode 100644 index 0000000..bd95170 --- /dev/null +++ b/jackson/src/test/java/org/fuin/objects4j/jackson/WeeklyOpeningHoursJacksonSerializerTest.java @@ -0,0 +1,46 @@ +/** + * Copyright (C) 2013 Future Invent Informationsmanagement GmbH. All rights + * reserved. + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see . + */ +package org.fuin.objects4j.jackson; + +import com.fasterxml.jackson.core.JsonProcessingException; +import org.fuin.objects4j.common.ConstraintViolationException; +import org.fuin.objects4j.core.WeeklyOpeningHours; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; + +/** + * Test for the {@link WeeklyOpeningHoursJacksonSerializer} class. + */ +public class WeeklyOpeningHoursJacksonSerializerTest { + + private static final String HOURS = "MON-FRI 06:00-18:00,SAT/SUN 06:00-12:00"; + + private static final String JSON = "{\"weeklyOpeningHours\":\"" + HOURS + "\"}"; + + @Test + public final void testMarshal() throws JsonProcessingException { + + final Data data = new Data(); + data.weeklyOpeningHours = new WeeklyOpeningHours(HOURS); + assertThat(JacksonHelper.toJson(data)).isEqualTo(JSON); + + } + +} diff --git a/jaxb/pom.xml b/jaxb/pom.xml index 7dd2257..e2b2a12 100644 --- a/jaxb/pom.xml +++ b/jaxb/pom.xml @@ -70,7 +70,7 @@ com.tngtech.archunit - archunit-junit5-api + archunit-junit5 test @@ -148,7 +148,11 @@ org.glassfish:jakarta.el org.hibernate.validator:hibernate-validator org.glassfish.jaxb:jaxb-runtime + com.tngtech.archunit:archunit-junit5 + + com.tngtech.archunit:archunit-junit5-api + diff --git a/jaxb/src/main/java/org/fuin/objects4j/jaxb/JaxbUtils.java b/jaxb/src/main/java/org/fuin/objects4j/jaxb/JaxbUtils.java index d66a8fe..7b0a520 100644 --- a/jaxb/src/main/java/org/fuin/objects4j/jaxb/JaxbUtils.java +++ b/jaxb/src/main/java/org/fuin/objects4j/jaxb/JaxbUtils.java @@ -38,7 +38,6 @@ public final class JaxbUtils { new HourRangesXmlAdapter(), new LocaleXmlAdapter(), new MultiDayOfTheWeekXmlAdapter(), - new PasswordXmlAdapter(), new PasswordSha512XmlAdapter(), new UserNameXmlAdapter(), new UUIDXmlAdapter(), diff --git a/jaxb/src/main/java/org/fuin/objects4j/jaxb/package-info.java b/jaxb/src/main/java/org/fuin/objects4j/jaxb/package-info.java index 482bf3f..e0a7827 100644 --- a/jaxb/src/main/java/org/fuin/objects4j/jaxb/package-info.java +++ b/jaxb/src/main/java/org/fuin/objects4j/jaxb/package-info.java @@ -9,7 +9,6 @@ @XmlJavaTypeAdapter(value = HourRangesXmlAdapter.class, type = HourRanges.class), @XmlJavaTypeAdapter(value = LocaleXmlAdapter.class, type = Locale.class), @XmlJavaTypeAdapter(value = MultiDayOfTheWeekXmlAdapter.class, type = MultiDayOfTheWeek.class), - @XmlJavaTypeAdapter(value = PasswordXmlAdapter.class, type = Password.class), @XmlJavaTypeAdapter(value = PasswordSha512XmlAdapter.class, type = PasswordSha512.class), @XmlJavaTypeAdapter(value = UserNameXmlAdapter.class, type = UserName.class), @XmlJavaTypeAdapter(value = UUIDXmlAdapter.class, type = UUID.class), @@ -27,7 +26,6 @@ import org.fuin.objects4j.core.HourRange; import org.fuin.objects4j.core.HourRanges; import org.fuin.objects4j.core.MultiDayOfTheWeek; -import org.fuin.objects4j.core.Password; import org.fuin.objects4j.core.PasswordSha512; import org.fuin.objects4j.core.UserName; import org.fuin.objects4j.core.WeeklyOpeningHours; diff --git a/jaxb/src/test/java/org/fuin/objects4j/jaxb/ArchitectureTest.java b/jaxb/src/test/java/org/fuin/objects4j/jaxb/ArchitectureTest.java index b94d6cb..57ee979 100644 --- a/jaxb/src/test/java/org/fuin/objects4j/jaxb/ArchitectureTest.java +++ b/jaxb/src/test/java/org/fuin/objects4j/jaxb/ArchitectureTest.java @@ -47,7 +47,8 @@ class ArchitectureTest { .onlyDependOnClassesThat() .resideInAnyPackage(JAXB_PACKAGE, COMMON_PACKAGE, CORE_PACKAGE, "java.lang..", "java.util..", - "jakarta.validation..", "jakarta.annotation..", "jakarta.xml.bind.."); + "jakarta.validation..", "jakarta.annotation..", "jakarta.xml.bind..", + "javax.annotation.concurrent"); } diff --git a/jaxb/src/test/java/org/fuin/objects4j/jaxb/Data.java b/jaxb/src/test/java/org/fuin/objects4j/jaxb/Data.java index 230cd62..4324431 100644 --- a/jaxb/src/test/java/org/fuin/objects4j/jaxb/Data.java +++ b/jaxb/src/test/java/org/fuin/objects4j/jaxb/Data.java @@ -29,7 +29,6 @@ import org.fuin.objects4j.core.HourRange; import org.fuin.objects4j.core.HourRanges; import org.fuin.objects4j.core.MultiDayOfTheWeek; -import org.fuin.objects4j.core.Password; import org.fuin.objects4j.core.PasswordSha512; import org.fuin.objects4j.core.UserName; import org.fuin.objects4j.core.WeeklyOpeningHours; @@ -48,9 +47,6 @@ public class Data { @XmlAttribute public EmailAddress email; - @XmlAttribute - public Password password; - @XmlAttribute public PasswordSha512 passwordSha512; diff --git a/jaxb/src/test/java/org/fuin/objects4j/jaxb/HourRangeConverterTest.java b/jaxb/src/test/java/org/fuin/objects4j/jaxb/HourRangeXmlAdapterTest.java similarity index 98% rename from jaxb/src/test/java/org/fuin/objects4j/jaxb/HourRangeConverterTest.java rename to jaxb/src/test/java/org/fuin/objects4j/jaxb/HourRangeXmlAdapterTest.java index 444daea..1362abb 100644 --- a/jaxb/src/test/java/org/fuin/objects4j/jaxb/HourRangeConverterTest.java +++ b/jaxb/src/test/java/org/fuin/objects4j/jaxb/HourRangeXmlAdapterTest.java @@ -26,7 +26,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.fuin.utils4j.jaxb.JaxbUtils.XML_PREFIX; -public class HourRangeConverterTest { +public class HourRangeXmlAdapterTest { private static final String XML = XML_PREFIX + ""; diff --git a/jaxb/src/test/java/org/fuin/objects4j/jaxb/HourRangesConverterTest.java b/jaxb/src/test/java/org/fuin/objects4j/jaxb/HourRangesXmlAdapterTest.java similarity index 98% rename from jaxb/src/test/java/org/fuin/objects4j/jaxb/HourRangesConverterTest.java rename to jaxb/src/test/java/org/fuin/objects4j/jaxb/HourRangesXmlAdapterTest.java index 26a3df4..6f2a0d2 100644 --- a/jaxb/src/test/java/org/fuin/objects4j/jaxb/HourRangesConverterTest.java +++ b/jaxb/src/test/java/org/fuin/objects4j/jaxb/HourRangesXmlAdapterTest.java @@ -26,7 +26,7 @@ import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.fuin.utils4j.jaxb.JaxbUtils.XML_PREFIX; -public class HourRangesConverterTest { +public class HourRangesXmlAdapterTest { private static final String XML = XML_PREFIX + ""; diff --git a/jaxb/src/test/java/org/fuin/objects4j/jaxb/PasswordSha512ConverterTest.java b/jaxb/src/test/java/org/fuin/objects4j/jaxb/PasswordSha512XmlAdapterTest.java similarity index 98% rename from jaxb/src/test/java/org/fuin/objects4j/jaxb/PasswordSha512ConverterTest.java rename to jaxb/src/test/java/org/fuin/objects4j/jaxb/PasswordSha512XmlAdapterTest.java index 64709b7..768862a 100644 --- a/jaxb/src/test/java/org/fuin/objects4j/jaxb/PasswordSha512ConverterTest.java +++ b/jaxb/src/test/java/org/fuin/objects4j/jaxb/PasswordSha512XmlAdapterTest.java @@ -27,7 +27,7 @@ import static org.fuin.utils4j.jaxb.JaxbUtils.XML_PREFIX; //CHECKSTYLE:OFF -public class PasswordSha512ConverterTest { +public class PasswordSha512XmlAdapterTest { private static final String HASH = "925f43c3cfb956bbe3c6aa8023ba7ad5cfa21d104186fffc69e768e55940d9653b1cd36fba614fba2e1844f4436da20f83750c6ec1db356da154691bdd71a9b1"; diff --git a/jpa/pom.xml b/jpa/pom.xml index a30431e..e75287c 100644 --- a/jpa/pom.xml +++ b/jpa/pom.xml @@ -70,7 +70,7 @@ com.tngtech.archunit - archunit-junit5-api + archunit-junit5 test @@ -155,7 +155,11 @@ org.hibernate.validator:hibernate-validator org.hibernate.orm:hibernate-core org.hsqldb:hsqldb + com.tngtech.archunit:archunit-junit5 + + com.tngtech.archunit:archunit-junit5-api + diff --git a/jpa/src/test/java/org/fuin/objects4j/jpa/ArchitectureTest.java b/jpa/src/test/java/org/fuin/objects4j/jpa/ArchitectureTest.java index 6fa0ce0..6fba8cf 100644 --- a/jpa/src/test/java/org/fuin/objects4j/jpa/ArchitectureTest.java +++ b/jpa/src/test/java/org/fuin/objects4j/jpa/ArchitectureTest.java @@ -47,7 +47,8 @@ class ArchitectureTest { .onlyDependOnClassesThat() .resideInAnyPackage(JPA_PACKAGE, COMMON_PACKAGE, CORE_PACKAGE, "java.lang..", "java.util..", - "jakarta.validation..", "jakarta.annotation..", "jakarta.persistence.."); + "jakarta.validation..", "jakarta.annotation..", "jakarta.persistence..", + "javax.annotation.concurrent"); } diff --git a/jsonb/pom.xml b/jsonb/pom.xml index 0e8b9b3..7374333 100644 --- a/jsonb/pom.xml +++ b/jsonb/pom.xml @@ -44,12 +44,6 @@ - - org.fuin - utils4j - test - - org.junit.jupiter junit-jupiter-api @@ -70,7 +64,7 @@ com.tngtech.archunit - archunit-junit5-api + archunit-junit5 test @@ -154,7 +148,11 @@ org.glassfish:jakarta.el org.hibernate.validator:hibernate-validator org.glassfish:jakarta.json + com.tngtech.archunit:archunit-junit5 + + com.tngtech.archunit:archunit-junit5-api + diff --git a/jsonb/src/main/java/org/fuin/objects4j/jsonb/JsonbUtils.java b/jsonb/src/main/java/org/fuin/objects4j/jsonb/JsonbUtils.java index be5329b..71ce7ec 100644 --- a/jsonb/src/main/java/org/fuin/objects4j/jsonb/JsonbUtils.java +++ b/jsonb/src/main/java/org/fuin/objects4j/jsonb/JsonbUtils.java @@ -15,7 +15,6 @@ public final class JsonbUtils { new HourRangesJsonbAdapter(), new LocaleJsonbAdapter(), new EmailAddressJsonbAdapter(), - new PasswordJsonbAdapter(), new CurrencyAmountJsonbAdapter(), new WeeklyOpeningHoursJsonbAdapter(), new UUIDJsonbAdapter(), diff --git a/jsonb/src/test/java/org/fuin/objects4j/jsonb/ArchitectureTest.java b/jsonb/src/test/java/org/fuin/objects4j/jsonb/ArchitectureTest.java index 3c0bbaf..2943333 100644 --- a/jsonb/src/test/java/org/fuin/objects4j/jsonb/ArchitectureTest.java +++ b/jsonb/src/test/java/org/fuin/objects4j/jsonb/ArchitectureTest.java @@ -47,7 +47,8 @@ class ArchitectureTest { .onlyDependOnClassesThat() .resideInAnyPackage(JSONB_PACKAGE, COMMON_PACKAGE, CORE_PACKAGE, "java.lang..", "java.util..", - "jakarta.validation..", "jakarta.annotation..", "jakarta.json.bind.."); + "jakarta.validation..", "jakarta.annotation..", "jakarta.json.bind..", + "javax.annotation.concurrent"); } diff --git a/jsonb/src/test/java/org/fuin/objects4j/jsonb/Data.java b/jsonb/src/test/java/org/fuin/objects4j/jsonb/Data.java index 8ae90c7..47cfcfe 100644 --- a/jsonb/src/test/java/org/fuin/objects4j/jsonb/Data.java +++ b/jsonb/src/test/java/org/fuin/objects4j/jsonb/Data.java @@ -27,7 +27,6 @@ import org.fuin.objects4j.core.HourRange; import org.fuin.objects4j.core.HourRanges; import org.fuin.objects4j.core.MultiDayOfTheWeek; -import org.fuin.objects4j.core.Password; import org.fuin.objects4j.core.PasswordSha512; import org.fuin.objects4j.core.UserName; import org.fuin.objects4j.core.WeeklyOpeningHours; @@ -45,9 +44,6 @@ public class Data { @JsonbProperty public EmailAddress email; - @JsonbProperty - public Password password; - @JsonbProperty public PasswordSha512 passwordSha512; diff --git a/jsonb/src/test/java/org/fuin/objects4j/jsonb/DayOfTheWeekConverterTest.java b/jsonb/src/test/java/org/fuin/objects4j/jsonb/DayOfTheWeekJsonbAdapterTest.java similarity index 98% rename from jsonb/src/test/java/org/fuin/objects4j/jsonb/DayOfTheWeekConverterTest.java rename to jsonb/src/test/java/org/fuin/objects4j/jsonb/DayOfTheWeekJsonbAdapterTest.java index 0ff74ab..539e83a 100644 --- a/jsonb/src/test/java/org/fuin/objects4j/jsonb/DayOfTheWeekConverterTest.java +++ b/jsonb/src/test/java/org/fuin/objects4j/jsonb/DayOfTheWeekJsonbAdapterTest.java @@ -28,7 +28,7 @@ /** * Test for the {@link DayOfTheWeekJsonbAdapter} class. */ -class DayOfTheWeekConverterTest { +class DayOfTheWeekJsonbAdapterTest { private static final String JSON = "{\"dayOfTheWeek\":\"FRI\"}"; diff --git a/jsonb/src/test/java/org/fuin/objects4j/jsonb/HourRangeJsonbAdapterTest.java b/jsonb/src/test/java/org/fuin/objects4j/jsonb/HourRangeJsonbAdapterTest.java index a42965e..fb03dde 100644 --- a/jsonb/src/test/java/org/fuin/objects4j/jsonb/HourRangeJsonbAdapterTest.java +++ b/jsonb/src/test/java/org/fuin/objects4j/jsonb/HourRangeJsonbAdapterTest.java @@ -1,17 +1,17 @@ /** * Copyright (C) 2013 Future Invent Informationsmanagement GmbH. All rights * reserved. - * + *

* This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 3 of the License, or (at your option) any * later version. - * + *

* This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. - * + *

* You should have received a copy of the GNU Lesser General Public License * along with this library. If not, see . */ @@ -25,15 +25,12 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.fuin.objects4j.jsonb.JsonbHelper.fromJson; import static org.fuin.objects4j.jsonb.JsonbHelper.toJson; -import static org.fuin.utils4j.jaxb.JaxbUtils.XML_PREFIX; /** * Test for the {@link HourRangeJsonbAdapter} class. */ class HourRangeJsonbAdapterTest { - private static final String XML = XML_PREFIX + ""; - private static final String JSON = "{\"hourRange\":\"00:00-24:00\"}"; @Test diff --git a/jsonb/src/test/java/org/fuin/objects4j/jsonb/WeeklyOpeningHoursConverterTest.java b/jsonb/src/test/java/org/fuin/objects4j/jsonb/WeeklyOpeningHoursJsonbAdapterTest.java similarity index 97% rename from jsonb/src/test/java/org/fuin/objects4j/jsonb/WeeklyOpeningHoursConverterTest.java rename to jsonb/src/test/java/org/fuin/objects4j/jsonb/WeeklyOpeningHoursJsonbAdapterTest.java index 470b921..97ebc9e 100644 --- a/jsonb/src/test/java/org/fuin/objects4j/jsonb/WeeklyOpeningHoursConverterTest.java +++ b/jsonb/src/test/java/org/fuin/objects4j/jsonb/WeeklyOpeningHoursJsonbAdapterTest.java @@ -29,7 +29,7 @@ /** * Test for the {@link WeeklyOpeningHoursJsonbAdapter} class. */ -public class WeeklyOpeningHoursConverterTest { +public class WeeklyOpeningHoursJsonbAdapterTest { private static final String HOURS = "MON-FRI 06:00-18:00,SAT/SUN 06:00-12:00"; diff --git a/junit/pom.xml b/junit/pom.xml index 86ac950..f6ce2d4 100644 --- a/junit/pom.xml +++ b/junit/pom.xml @@ -61,7 +61,7 @@ com.tngtech.archunit - archunit-junit5-api + archunit-junit5 test @@ -113,7 +113,11 @@ org.fuin.objects4j:objects4j-jpa org.fuin.objects4j:objects4j-jsonb org.fuin.objects4j:objects4j-ui + com.tngtech.archunit:archunit-junit5 + + com.tngtech.archunit:archunit-junit5-api + diff --git a/pom.xml b/pom.xml index 198772f..8a3baef 100644 --- a/pom.xml +++ b/pom.xml @@ -31,6 +31,7 @@ ${project.basedir}/../junit/target/site/jacoco-aggregate/jacoco.xml + 2.16.1 @@ -165,7 +166,7 @@ com.tngtech.archunit - archunit-junit5-api + archunit-junit5 1.2.1 @@ -289,6 +290,24 @@ 1.19.4 + + com.fasterxml.jackson.core + jackson-annotations + ${jackson.version} + + + + com.fasterxml.jackson.core + jackson-core + ${jackson.version} + + + + com.fasterxml.jackson.core + jackson-databind + ${jackson.version} + + @@ -367,6 +386,7 @@ ui core jaxb + jackson jpa jsonb junit diff --git a/ui/pom.xml b/ui/pom.xml index e78fc0b..f5b3b8a 100644 --- a/ui/pom.xml +++ b/ui/pom.xml @@ -59,7 +59,7 @@ com.tngtech.archunit - archunit-junit5-api + archunit-junit5 test @@ -136,7 +136,11 @@ jakarta.el:jakarta.el-api org.glassfish:jakarta.el org.hibernate.validator:hibernate-validator + com.tngtech.archunit:archunit-junit5 + + com.tngtech.archunit:archunit-junit5-api + diff --git a/ui/src/test/java/org/fuin/objects4j/ui/ArchitectureTest.java b/ui/src/test/java/org/fuin/objects4j/ui/ArchitectureTest.java index 6b4f610..95e32ba 100644 --- a/ui/src/test/java/org/fuin/objects4j/ui/ArchitectureTest.java +++ b/ui/src/test/java/org/fuin/objects4j/ui/ArchitectureTest.java @@ -43,7 +43,8 @@ class ArchitectureTest { .onlyDependOnClassesThat() .resideInAnyPackage(COMMON_PACKAGE, UI_PACKAGE, "java.lang..", "java.util..", "java.io..", "java.text..", - "jakarta.validation..", "jakarta.annotation..", "jakarta.enterprise.inject.."); + "jakarta.validation..", "jakarta.annotation..", "jakarta.enterprise.inject..", + "javax.annotation.concurrent"); }