Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Spring Boot JPA demo application showcasing FriendlyId with JPA, REST API, and OpenFeign

### Changed
- **Breaking**: Renamed `FriendlyIdFormat.RAW` to `FriendlyIdFormat.UUID` for clarity
- Upgraded from Java 8 to Java 21
- Upgraded from Spring Boot 2.2.2 to 3.4.1
- Upgraded from JUnit 4 to JUnit 5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public UUID deserialize(JsonParser parser, DeserializationContext ctxt) {
public ValueDeserializer<?> createContextual(DeserializationContext ctxt, BeanProperty property) {
if (property != null) {
var annotation = property.getAnnotation(IdFormat.class);
if (annotation != null && annotation.value() == FriendlyIdFormat.RAW) {
if (annotation != null && annotation.value() == FriendlyIdFormat.UUID) {
return new FriendlyIdDeserializer(false);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* enabling automatic conversion between UUID values and their FriendlyId string representation.
* </p>
* <p>
* By default, UUIDs are serialized as Base62 FriendlyIds. Use {@link FriendlyIdFormat#RAW}
* By default, UUIDs are serialized as Base62 FriendlyIds. Use {@link FriendlyIdFormat#UUID}
* to serialize UUIDs in standard format while still accepting both formats on deserialization.
* Per-field format can always be overridden with {@link com.devskiller.friendly_id.IdFormat @IdFormat}.
* </p>
Expand All @@ -31,7 +31,7 @@ public FriendlyIdModule() {
/**
* Creates a module with the specified default serialization format.
* <p>
* When {@link FriendlyIdFormat#RAW} is used, UUIDs are serialized in standard format
* When {@link FriendlyIdFormat#UUID} is used, UUIDs are serialized in standard format
* but deserialization still accepts both standard UUIDs and Base62 FriendlyIds.
* Per-field format can be overridden with {@link com.devskiller.friendly_id.IdFormat @IdFormat}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void serialize(UUID uuid, JsonGenerator jsonGenerator, SerializationConte
public ValueSerializer<?> createContextual(SerializationContext ctxt, BeanProperty property) {
if (property != null) {
IdFormat annotation = property.getAnnotation(IdFormat.class);
if (annotation != null && annotation.value() == FriendlyIdFormat.RAW) {
if (annotation != null && annotation.value() == FriendlyIdFormat.UUID) {
return new FriendlyIdSerializer(false);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
import com.devskiller.friendly_id.IdFormat;

public record Bar(
@IdFormat(FriendlyIdFormat.RAW) UUID rawUuid,
@IdFormat(FriendlyIdFormat.UUID) UUID rawUuid,
UUID friendlyId
) {}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
import com.devskiller.friendly_id.IdFormat;

public record Foo(
@IdFormat(FriendlyIdFormat.RAW) UUID rawUuid,
@IdFormat(FriendlyIdFormat.UUID) UUID rawUuid,
UUID friendlyId
) {}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class RawFormatModuleTest {
private final UUID uuid = UUID.fromString("f088ce5b-9279-4cc3-946a-c15ad740dd6d");

private final JsonMapper mapper = JsonMapper.builder()
.addModule(new FriendlyIdModule(FriendlyIdFormat.RAW))
.addModule(new FriendlyIdModule(FriendlyIdFormat.UUID))
.build();

@Test
Expand Down Expand Up @@ -48,9 +48,9 @@ void shouldRespectPerFieldOverrideWhenModuleIsRaw() {

String json = mapper.writeValueAsString(foo);

// rawUuid has @IdFormat(RAW) -> standard format
// rawUuid has @IdFormat(UUID) -> standard format
assertThat(json).contains("\"rawUuid\":\"f088ce5b-9279-4cc3-946a-c15ad740dd6d\"");
// friendlyId has no annotation, module default is RAW -> standard format
// friendlyId has no annotation, module default is UUID -> standard format
assertThat(json).contains("\"friendlyId\":\"f088ce5b-9279-4cc3-946a-c15ad740dd6d\"");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public Object findSerializer(Annotated annotatedMethod) {
IdFormat annotation = _findAnnotation(annotatedMethod, IdFormat.class);
if (annotatedMethod.getRawType() == UUID.class && annotation != null) {
return switch (annotation.value()) {
case RAW -> UUIDSerializer.class;
case UUID -> UUIDSerializer.class;
case URL62 -> FriendlyIdSerializer.class;
};
}
Expand All @@ -33,7 +33,7 @@ public Object findDeserializer(Annotated annotatedMethod) {
var annotation = _findAnnotation(annotatedMethod, IdFormat.class);
if (rawDeserializationType(annotatedMethod) == UUID.class && annotation != null) {
return switch (annotation.value()) {
case RAW -> UUIDDeserializer.class;
case UUID -> UUIDDeserializer.class;
case URL62 -> FriendlyIdDeserializer.class;
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

public class Bar {

@IdFormat(FriendlyIdFormat.RAW)
@IdFormat(FriendlyIdFormat.UUID)
private final UUID rawUuid;

private final UUID friendlyId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

public class Foo {

@IdFormat(FriendlyIdFormat.RAW)
@IdFormat(FriendlyIdFormat.UUID)
private UUID rawUuid;

private UUID friendlyId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class RawFormatModuleTest {
private final UUID uuid = UUID.fromString("f088ce5b-9279-4cc3-946a-c15ad740dd6d");

private final ObjectMapper mapper = new ObjectMapper()
.registerModule(new FriendlyIdJackson2Module(FriendlyIdFormat.RAW));
.registerModule(new FriendlyIdJackson2Module(FriendlyIdFormat.UUID));

@Test
void shouldSerializeUuidInStandardFormat() throws Exception {
Expand Down Expand Up @@ -49,9 +49,9 @@ void shouldRespectPerFieldAnnotationWhenModuleIsRaw() throws Exception {

String json = mapper.writeValueAsString(foo);

// rawUuid has @IdFormat(RAW) -> standard format
// rawUuid has @IdFormat(UUID) -> standard format
assertThat(json).contains("\"rawUuid\":\"f088ce5b-9279-4cc3-946a-c15ad740dd6d\"");
// friendlyId has no annotation, module default is RAW -> standard format
// friendlyId has no annotation, module default is UUID -> standard format
assertThat(json).contains("\"friendlyId\":\"f088ce5b-9279-4cc3-946a-c15ad740dd6d\"");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
* Example record demonstrating different UUID serialization formats.
*
* @param id UUID serialized as FriendlyId string (default behavior)
* @param rawId UUID serialized as raw UUID string
* @param rawId UUID serialized in standard UUID format
* @param friendlyUuid UUID explicitly serialized as FriendlyId string
* @param friendlyId FriendlyId value object type
*/
public record Item(
UUID id,
@IdFormat(FriendlyIdFormat.RAW) UUID rawId,
@IdFormat(FriendlyIdFormat.UUID) UUID rawId,
@IdFormat(FriendlyIdFormat.URL62) UUID friendlyUuid,
FriendlyId friendlyId
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
* Example record demonstrating different UUID serialization formats.
*
* @param id UUID serialized as FriendlyId string (default behavior)
* @param rawId UUID serialized as raw UUID string
* @param rawId UUID serialized in standard UUID format
* @param friendlyUuid UUID explicitly serialized as FriendlyId string
* @param friendlyId FriendlyId value object type
*/
public record Item(
UUID id,
@IdFormat(FriendlyIdFormat.RAW) UUID rawId,
@IdFormat(FriendlyIdFormat.UUID) UUID rawId,
@IdFormat(FriendlyIdFormat.URL62) UUID friendlyUuid,
FriendlyId friendlyId
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
* Example record demonstrating different UUID serialization formats.
*
* @param id UUID serialized as FriendlyId string (default behavior)
* @param rawId UUID serialized as raw UUID string
* @param rawId UUID serialized in standard UUID format
* @param friendlyUuid UUID explicitly serialized as FriendlyId string
* @param friendlyId FriendlyId value object type
*/
public record Item(
UUID id,
@IdFormat(FriendlyIdFormat.RAW) UUID rawId,
@IdFormat(FriendlyIdFormat.UUID) UUID rawId,
@IdFormat(FriendlyIdFormat.URL62) UUID friendlyUuid,
FriendlyId friendlyId
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
* Example record demonstrating different UUID serialization formats.
*
* @param id UUID serialized as FriendlyId string (default behavior)
* @param rawId UUID serialized as raw UUID string
* @param rawId UUID serialized in standard UUID format
* @param friendlyUuid UUID explicitly serialized as FriendlyId string
* @param friendlyId FriendlyId value object type
*/
public record Item(
UUID id,
@IdFormat(FriendlyIdFormat.RAW) UUID rawId,
@IdFormat(FriendlyIdFormat.UUID) UUID rawId,
@IdFormat(FriendlyIdFormat.URL62) UUID friendlyUuid,
FriendlyId friendlyId
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public enum FriendlyIdFormat {
URL62,

/**
* Leave this ID as is (without conversion)
* Standard UUID format (without Base62 conversion)
*/
RAW
UUID
}