我如何将杰克逊DTO转换为jsonschema



我正在尝试在SDR不合适的情况下模仿Spring Data Rest的API,例如登录或密码重置路由。我有这个dto

public class PasswordCredential implements 
AuthenticationProvider<UsernamePasswordAuthenticationToken> {
@Email
@NotNull
@NotEmpty
private final String user;
@NotNull
@NotEmpty
private final CharSequence pass;
@JsonCreator
public PasswordCredential(
    @Nullable @JsonProperty( value = "user", access = JsonProperty.Access.WRITE_ONLY ) String user,
    @Nullable @JsonProperty( value = "pass", access = JsonProperty.Access.WRITE_ONLY ) CharSequence pass
) {
    this.user = user;
    this.pass = pass;
}

我想将其转换为JsonSchema,以便我可以像SDR一样返回。我该如何完成?

我不熟悉春季,但是我们使用gson将DTO转换为字符串。这只是一个测试,但是您明白了。

import com.google.gson.GsonBuilder;
public class NewMain {  
    static public class PasswordCredential {
        private String user;
        private CharSequence pass;
    } 
    public static void main(String[] args) {
        PasswordCredential pc = new PasswordCredential();
        pc.pass = "password";
        pc.user = "myuser";
        GsonBuilder builder = new GsonBuilder();
        System.out.println(builder.create().toJson(pc));
    }
}

如果那不是您在寻找的话,请告诉我,所以我可以扩展我的答案。

最新更新