0

I'm trying to convert a JSON (from REST API) to a Java Object using Jackson. But when I run this code. Netbeans keeps running but nothing changes.. My hash works fine, so I don't think my URL is wrong..

Is my mapper wrongly configured? I can't find a solution..

 public Beheerder meldAan(String email, String wachtwoord){
    if (email == null || wachtwoord == null) {
        throw new IllegalArgumentException("Gebruikersnaam en wachtwoord moeten worden ingevuld.");
    }
     Beheerder beheerder = null;
    try {

        List<Beheerder> beheerders = repo.geefAlleBeheerders();

        if (controlleerBeheerder(beheerders, email)) {
            throw new IllegalArgumentException("Gebruikersnaam is verkeerd ingevuld.");
        }

        String hash = sha256(wachtwoord);
        //URL jsonUrl = new URL("https://studservice.hogent.be/auth/" + email + "/" + hash);

        ObjectMapper mapper = new ObjectMapper();

        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);            
        beheerder = mapper.readValue(jsonUrl, Beheerder.class);

        if (beheerder == null) {
            throw new IllegalArgumentException("Gelieve een correct wachtwoord in te geven");
        }

        return beheerder;
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch(IOException e){
        e.printStackTrace();
    }

    return beheerder;

}


public class Beheerder {

private int beheerderId;
private String faculteit;
private String naam;
private String foto;
private String type;
private String voornaam;
private String email;
private boolean isHoofdbeheerder;

public Beheerder(String f, String fm, String foto, String type, String vm, String email){
    this.faculteit = f;
    this.type = type;
    this.naam = fm;
    this.foto = foto;
    this.voornaam = vm;
    this.email = email;
} //With some getters and setters.. 
3
  • 1
    How does your JSON look like? Commented May 4, 2016 at 9:05
  • 2
    I have a feeling there's something missing. The code you posted doesn't seem to produce an endless loop (at least that's what I think you're describing). Did you debug? Commented May 4, 2016 at 9:06
  • {"FACULTEIT":"FBO","NAAM":"De Durpel","BASE64FOTO":"binary code//","TYPE":"student","VOORNAAM":"Kas","EMAIL":"[email protected]"} Commented May 4, 2016 at 9:44

2 Answers 2

1

I assume there is a problem retrieving the data from the remote server. You should separate these concerns: Have one method fetching the data and one method deserializing it. You can test the JSON mapping then separately, f.e. with a String input from a unit test or a separate main class.

Try loading the JSON manually from your browser or command line with curl/wget as well. (Could be a firewall issue which would explain that it takes so long instead of immediate failure.)

Sign up to request clarification or add additional context in comments.

1 Comment

If you have the data and separated the methods (fetching / deserializing), call the deserializing with the data manually. If that blocks there is really something fishy.
0

In the picture you can see the variables when I debugged it.. Debug session

String hash = sha256(wachtwoord);
        String json = "{\"FACULTEIT\":\"FBO\",\"NAAM\":\"De Durpel\",\"BASE64FOTO\":\"zezz//\",\"TYPE\":\"student\",\"VOORNAAM\":\"Kas\",\"EMAIL\":\"[email protected]‌​gent.be\"}";
        ObjectMapper mapper = new ObjectMapper();

        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);            
        beheerder = mapper.readValue(json, Beheerder.class);

        if (beheerder == null) {
            throw new IllegalArgumentException("Gelieve een correct wachtwoord in te geven");
        }

My 'Beheerder' object stays null when I do it manually. But It is a problem retrieving the data I guess!

1 Comment

You can enable SSL debugging in Java with with system property javax.net.debug set to all.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.