Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

access to ProcessingMessage internal map #193

Open
sharonbn1 opened this issue Jul 25, 2016 · 3 comments
Open

access to ProcessingMessage internal map #193

sharonbn1 opened this issue Jul 25, 2016 · 3 comments

Comments

@sharonbn1
Copy link

I would like to get access to the internal map of ProcessingMessage.
The reason: I would like to know the name of the property that failed validation
The rationale: I use json schema to enforce password policy. I would like to detect that provided username and/or password failed validation and give the recomended general error message
right now I scrape the toString() output... seems redundant
alternatively perhaps ProcessingMessage can be enhanced to include getPropertyName() ?

@sharonbn1
Copy link
Author

I now see that missing required properties are handled in one msg, so perhaps ProcessingReport can give list of failed properties?

@priyaaggarwal24
Copy link

Hi @sharonbn1

I think I understand your situation, because few days back I also wanted to request for this map field access. But there's already another option for accessing things in that map which I discovered few hours back. This option is using ProcessingMessage.asJson() method. I am pasting below a code snippet to show how it can be used

final Iterator<ProcessingMessage> processingMessageIterator = jsonSchemaValidationException.getProcessingReport().iterator();
List<String> messageList = new ArrayList<>();

while (processingMessageIterator.hasNext()) {
    ProcessingMessage processingMessage = processingMessageIterator.next();
    JsonNode jsonNode = processingMessage.asJson();
    String fieldJsonSchemaPath = jsonNode.get("schema").get("pointer").toString();
    String validationMessage = jsonNode.get("message").toString();
    messageList.add(String.format("field: %s , validationMessage: %s",fieldJsonSchemaPath, validationMessage));
}

whichever field you wish to get from that map, you can get that like this

//asJson() is a public method and gives every information that the map would
JsonNode jsonNode = processingMessage.asJson().get(mapKey);

the keys in that map are accessible as this JsonNode fields.

Hope this helps you!
Priya

@sharonbn1
Copy link
Author

Priya,
thanks for the answer. It is helpful but it is just another workaround. You should know that in case of missing or unwanted fields, the name of the field does not apear under scema -> pointer

I will rephrase my request - instead of getting access to the internal map, I would like a method that returns the names of the json properties that failed the validation process

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants