1

I'm trying to mimic Spring Data REST's APIs in cases where SDR isn't a good fit, such as a login or password reset route. I have this 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;
}

I would like to convert it to a JsonSchema so that I can return it as SDR would. How can I accomplish this?

xenoterracide
  • 16,274
  • 24
  • 118
  • 243

1 Answers1

-1

I'm not familiar with Spring, but we convert DTOs to string using Gson. This is just a test, but you get the idea.

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));
    }

}

If that's not what you're looking let me know, so I can expand on my answer.

John Manko
  • 1,828
  • 27
  • 51