Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permit UUID by default #223

Merged
merged 2 commits into from
Jan 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
import java.util.Map;
import java.util.Set;
import java.util.TimeZone;
import java.util.UUID;

import lombok.Builder;
import lombok.extern.slf4j.Slf4j;

Expand All @@ -54,6 +56,7 @@
* <li>Primitive types such as {@code int} or {@code double} or the boxed equivalents
* <li>{@link String}
* <li>{@link java.util.Date}
* <li>{@link java.util.UUID}
* <li>The {@code java.time} classes:
* <ul>
* <li>{@link java.time.DayOfWeek}
Expand Down Expand Up @@ -125,41 +128,44 @@ private static final class InvocationJsonSerializer
addClassPair(boolean.class, "boolean");
addClassPair(char.class, "char");

addClassPair(Byte.class, "Byte");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no need to duplicate the class simple name like this. Just get it from the class directly.

addClassPair(Short.class, "Short");
addClassPair(Integer.class, "Integer");
addClassPair(Long.class, "Long");
addClassPair(Float.class, "Float");
addClassPair(Float.class, "Float");
addClassPair(Float.class, "Float");
Comment on lines -132 to -134
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note the duplication here, this has been removed.

addClassPair(Double.class, "Double");
addClassPair(Boolean.class, "Boolean");
addClassPair(Character.class, "Character");

addClassPair(BigDecimal.class, "BigDecimal");
addClassPair(String.class, "String");
addClassPair(Date.class, "Date");

addClassPair(DayOfWeek.class, "DayOfWeek");
addClassPair(Duration.class, "Duration");
addClassPair(Instant.class, "Instant");
addClassPair(LocalDate.class, "LocalDate");
addClassPair(LocalDateTime.class, "LocalDateTime");
addClassPair(Month.class, "Month");
addClassPair(MonthDay.class, "MonthDay");
addClassPair(Period.class, "Period");
addClassPair(Year.class, "Year");
addClassPair(YearMonth.class, "YearMonth");
addClassPair(ZoneOffset.class, "ZoneOffset");
addClassPair(DayOfWeek.class, "DayOfWeek");
addClassPair(ChronoUnit.class, "ChronoUnit");

addClassPair(Transaction.class, "Transaction");
addClass(Byte.class);
addClass(Short.class);
addClass(Integer.class);
addClass(Long.class);
addClass(Float.class);
addClass(Double.class);
addClass(Boolean.class);
addClass(Character.class);

addClass(BigDecimal.class);
addClass(String.class);
addClass(Date.class);
addClass(UUID.class);

addClass(DayOfWeek.class);
addClass(Duration.class);
addClass(Instant.class);
addClass(LocalDate.class);
addClass(LocalDateTime.class);
addClass(Month.class);
addClass(MonthDay.class);
addClass(Period.class);
addClass(Year.class);
addClass(YearMonth.class);
addClass(ZoneOffset.class);
addClass(DayOfWeek.class);
addClass(ChronoUnit.class);

addClass(Transaction.class);
addClassPair(TransactionContextPlaceholder.class, "TransactionContext");

serializableClasses.forEach(clazz -> addClassPair(clazz, clazz.getName()));
}

private void addClass(Class<?> clazz) {
addClassPair(clazz, clazz.getSimpleName());
}

private void addClassPair(Class<?> clazz, String name) {
classToName.put(clazz, name);
nameToClass.put(name, clazz);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Stream;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Assertions;
Expand Down Expand Up @@ -185,6 +186,13 @@ void testMDC() {
new Invocation(CLASS_NAME, METHOD_NAME, primitives, values, Map.of("A", "1", "B", "2")));
}

@Test
void testUUID() {
Class<?>[] primitives = {UUID.class};
Object[] values = {UUID.randomUUID()};
check(new Invocation(CLASS_NAME, METHOD_NAME, primitives, values));
}

void check(Invocation invocation) {
Invocation deserialized = serdeser(invocation);
Assertions.assertEquals(deserialized, serdeser(invocation));
Expand Down