Skip to content

Commit

Permalink
Deprecate Json*Serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
emlun committed Mar 29, 2022
1 parent f68e7c0 commit d2753cb
Show file tree
Hide file tree
Showing 14 changed files with 74 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.stream.Stream;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NonNull;

/**
Expand Down Expand Up @@ -77,25 +78,27 @@ public enum AttestationConveyancePreference implements JsonStringSerializable {
*/
DIRECT("direct");

@NonNull private final String id;
@Getter @NonNull private final String value;

private static Optional<AttestationConveyancePreference> fromString(@NonNull String id) {
return Stream.of(values()).filter(v -> v.id.equals(id)).findAny();
private static Optional<AttestationConveyancePreference> fromString(@NonNull String value) {
return Stream.of(values()).filter(v -> v.value.equals(value)).findAny();
}

@JsonCreator
private static AttestationConveyancePreference fromJsonString(@NonNull String id) {
return fromString(id)
private static AttestationConveyancePreference fromJsonString(@NonNull String value) {
return fromString(value)
.orElseThrow(
() ->
new IllegalArgumentException(
String.format(
"Unknown %s value: %s",
AttestationConveyancePreference.class.getSimpleName(), id)));
AttestationConveyancePreference.class.getSimpleName(), value)));
}

@Override
@Deprecated
/** @deprecated Use {@link #getValue()} instead. */
public String toJsonString() {
return id;
return value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.Optional;
import java.util.stream.Stream;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NonNull;

/**
Expand Down Expand Up @@ -73,25 +74,27 @@ public enum AuthenticatorAttachment implements JsonStringSerializable {
*/
PLATFORM("platform");

@NonNull private final String id;
@Getter @NonNull private final String value;

private static Optional<AuthenticatorAttachment> fromString(@NonNull String id) {
return Stream.of(values()).filter(v -> v.id.equals(id)).findAny();
private static Optional<AuthenticatorAttachment> fromString(@NonNull String value) {
return Stream.of(values()).filter(v -> v.value.equals(value)).findAny();
}

@JsonCreator
private static AuthenticatorAttachment fromJsonString(@NonNull String id) {
return fromString(id)
private static AuthenticatorAttachment fromJsonString(@NonNull String value) {
return fromString(value)
.orElseThrow(
() ->
new IllegalArgumentException(
String.format(
"Unknown %s value: %s",
AuthenticatorAttachment.class.getSimpleName(), id)));
AuthenticatorAttachment.class.getSimpleName(), value)));
}

@Override
@Deprecated
/** @deprecated Use {@link #getValue()} instead. */
public String toJsonString() {
return id;
return value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ public static AuthenticatorTransport fromU2fTransport(Transport transport) {
}

@Override
@Deprecated
/** @deprecated Use {@link #getId()} instead. */
public String toJsonString() {
return id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,9 @@ public String getHex() {
return BinaryUtil.toHex(bytes);
}

/** Used by JSON serializer. */
@Override
@Deprecated
/** @deprecated Use {@link #getBase64Url()} instead. */
public String toJsonString() {
return base64url;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ private static COSEAlgorithmIdentifier fromJson(long id) {
}

@Override
@Deprecated
/** @deprecated Use {@link #getId()} instead. */
public long toJsonNumber() {
return id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.Optional;
import java.util.stream.Stream;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NonNull;

/**
Expand All @@ -51,7 +52,7 @@
public enum PublicKeyCredentialType implements JsonStringSerializable {
PUBLIC_KEY("public-key");

@NonNull private final String id;
@Getter @NonNull private final String id;

private static Optional<PublicKeyCredentialType> fromString(@NonNull String id) {
return Stream.of(values()).filter(v -> v.id.equals(id)).findAny();
Expand All @@ -69,6 +70,8 @@ private static PublicKeyCredentialType fromJsonString(@NonNull String id) {
}

@Override
@Deprecated
/** @deprecated Use {@link #getId()} instead. */
public String toJsonString() {
return id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.Optional;
import java.util.stream.Stream;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NonNull;

/**
Expand Down Expand Up @@ -96,24 +97,27 @@ public enum ResidentKeyRequirement implements JsonStringSerializable {
*/
REQUIRED("required");

@NonNull private final String id;
@Getter @NonNull private final String value;

private static Optional<ResidentKeyRequirement> fromString(@NonNull String id) {
return Stream.of(values()).filter(v -> v.id.equals(id)).findAny();
private static Optional<ResidentKeyRequirement> fromString(@NonNull String value) {
return Stream.of(values()).filter(v -> v.value.equals(value)).findAny();
}

@JsonCreator
private static ResidentKeyRequirement fromJsonString(@NonNull String id) {
return fromString(id)
private static ResidentKeyRequirement fromJsonString(@NonNull String value) {
return fromString(value)
.orElseThrow(
() ->
new IllegalArgumentException(
String.format(
"Unknown %s value: %s", ResidentKeyRequirement.class.getSimpleName(), id)));
"Unknown %s value: %s",
ResidentKeyRequirement.class.getSimpleName(), value)));
}

@Override
@Deprecated
/** @deprecated Use {@link #getValue()} instead. */
public String toJsonString() {
return id;
return value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.Arrays;
import java.util.Optional;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NonNull;

/**
Expand Down Expand Up @@ -58,24 +59,26 @@ public enum TokenBindingStatus implements JsonStringSerializable {
*/
SUPPORTED("supported");

@NonNull private final String id;
@Getter @NonNull private final String value;

private static Optional<TokenBindingStatus> fromString(@NonNull String value) {
return Arrays.stream(values()).filter(v -> v.id.equals(value)).findAny();
return Arrays.stream(values()).filter(v -> v.value.equals(value)).findAny();
}

@JsonCreator
public static TokenBindingStatus fromJsonString(@NonNull String id) {
return fromString(id)
public static TokenBindingStatus fromJsonString(@NonNull String value) {
return fromString(value)
.orElseThrow(
() ->
new IllegalArgumentException(
String.format(
"Unknown %s value: %s", TokenBindingStatus.class.getSimpleName(), id)));
"Unknown %s value: %s", TokenBindingStatus.class.getSimpleName(), value)));
}

@Override
@Deprecated
/** @deprecated Use {@link #getValue()} instead. */
public String toJsonString() {
return id;
return value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.Optional;
import java.util.stream.Stream;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NonNull;

/**
Expand Down Expand Up @@ -66,25 +67,27 @@ public enum UserVerificationRequirement implements JsonStringSerializable {
*/
REQUIRED("required");

@NonNull private final String id;
@Getter @NonNull private final String value;

private static Optional<UserVerificationRequirement> fromString(@NonNull String id) {
return Stream.of(values()).filter(v -> v.id.equals(id)).findAny();
private static Optional<UserVerificationRequirement> fromString(@NonNull String value) {
return Stream.of(values()).filter(v -> v.value.equals(value)).findAny();
}

@JsonCreator
private static UserVerificationRequirement fromJsonString(@NonNull String id) {
return fromString(id)
private static UserVerificationRequirement fromJsonString(@NonNull String value) {
return fromString(value)
.orElseThrow(
() ->
new IllegalArgumentException(
String.format(
"Unknown %s value: %s",
UserVerificationRequirement.class.getSimpleName(), id)));
UserVerificationRequirement.class.getSimpleName(), value)));
}

@Override
@Deprecated
/** @deprecated Use {@link #getValue()} instead. */
public String toJsonString() {
return id;
return value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ static Optional<DocumentStatus> fromString(@NonNull String id) {
return Stream.of(values()).filter(v -> v.id.equals(id)).findAny();
}

/** Used by JSON serializer. */
@Override
@Deprecated
/** @deprecated This will be removed in the next major version release. */
public String toJsonString() {
return id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@

package com.yubico.internal.util.json;

@Deprecated
/** @deprecated This will be removed in the next major version. */
public interface JsonLongSerializable {

@Deprecated
/** @deprecated This will be removed in the next major version. */
long toJsonNumber();
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import com.fasterxml.jackson.databind.SerializerProvider;
import java.io.IOException;

@Deprecated
/** @deprecated This will be removed in the next major version. */
public class JsonLongSerializer<T extends JsonLongSerializable> extends JsonSerializer<T> {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@

package com.yubico.internal.util.json;

@Deprecated
/** @deprecated This will be removed in the next major version. */
public interface JsonStringSerializable {

@Deprecated
/** @deprecated This will be removed in the next major version. */
String toJsonString();
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import com.fasterxml.jackson.databind.SerializerProvider;
import java.io.IOException;

@Deprecated
/** @deprecated This will be removed in the next major version. */
public class JsonStringSerializer<T extends JsonStringSerializable> extends JsonSerializer<T> {

@Override
Expand Down

0 comments on commit d2753cb

Please sign in to comment.