Update configuration for badges to use URL instead of String
This commit is contained in:
parent
aa1c37fe26
commit
6478210330
|
@ -7,16 +7,19 @@ package org.whispersystems.textsecuregcm.configuration;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||||
|
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||||
|
import java.net.URL;
|
||||||
import javax.validation.constraints.NotEmpty;
|
import javax.validation.constraints.NotEmpty;
|
||||||
|
|
||||||
public class BadgeConfiguration {
|
public class BadgeConfiguration {
|
||||||
private final String name;
|
private final String name;
|
||||||
private final String imageUrl;
|
private final URL imageUrl;
|
||||||
|
|
||||||
@JsonCreator
|
@JsonCreator
|
||||||
public BadgeConfiguration(
|
public BadgeConfiguration(
|
||||||
@JsonProperty("name") final String name,
|
@JsonProperty("name") final String name,
|
||||||
@JsonProperty("imageUrl") final String imageUrl) {
|
@JsonProperty("imageUrl") @JsonDeserialize(converter = URLDeserializationConverter.class) final URL imageUrl) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.imageUrl = imageUrl;
|
this.imageUrl = imageUrl;
|
||||||
}
|
}
|
||||||
|
@ -27,7 +30,9 @@ public class BadgeConfiguration {
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotEmpty
|
@NotEmpty
|
||||||
public String getImageUrl() {
|
@JsonSerialize(converter = URLSerializationConverter.class)
|
||||||
|
public URL getImageUrl() {
|
||||||
return imageUrl;
|
return imageUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2021 Signal Messenger, LLC
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.whispersystems.textsecuregcm.configuration;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.util.StdConverter;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
final class URLDeserializationConverter extends StdConverter<String, URL> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public URL convert(final String value) {
|
||||||
|
try {
|
||||||
|
return new URL(value);
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
throw new IllegalArgumentException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2021 Signal Messenger, LLC
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.whispersystems.textsecuregcm.configuration;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.util.StdConverter;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
final class URLSerializationConverter extends StdConverter<URL, String> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String convert(final URL value) {
|
||||||
|
return value.toString();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue