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

Handle cases where ExpressionEvaluationDetails#targetValue is not a… #710

Merged
merged 1 commit into from
Mar 2, 2022

Conversation

lacikaaa
Copy link
Contributor

…n array

For single values the API might return with a single value instead of an array with one element. In that case the following error is produced:

com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.util.ArrayList<java.lang.Object>` out of VALUE_STRING token
 at [Source: (String)"{"policyDefinitionDisplayName":"Allowed resource types","policySetDefinitionDisplayName":"webapp","evaluationDetails":{"evaluatedExpressions":[{"result":"False","expression":"type","path":"type","expressionValue":"Microsoft.ApiManagement/service","targetValue":"Microsoft.Resources/resourceGroups","operator":"In"}]},"policyDefinitionId":"/providers/Microsoft.Authorization/policyDefinitions/a08ec900-254a-4555-9bf5-e42af04b5c5c","policySetDefinitionId":"/providers/Microsoft.Management/managementGro"[truncated 692 chars]; line: 1, column: 262] (through reference chain: com.microsoft.azure.CloudError["additionalInfo"]->java.util.ArrayList[1]->com.microsoft.azure.PolicyViolationErrorInfo["evaluationDetails"]->com.microsoft.azure.EvaluationDetails["evaluatedExpressions"]->java.util.ArrayList[0]->com.microsoft.azure.ExpressionEvaluationDetails["targetValue"])

	at com.fasterxml.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:59)
	at com.fasterxml.jackson.databind.DeserializationContext.reportInputMismatch(DeserializationContext.java:1445)
	at com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1219)
	at com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1129)
	at com.fasterxml.jackson.databind.deser.std.StringCollectionDeserializer.handleNonArray(StringCollectionDeserializer.java:274)
	at com.fasterxml.jackson.databind.deser.std.StringCollectionDeserializer.deserialize(StringCollectionDeserializer.java:183)
	at com.fasterxml.jackson.databind.deser.std.StringCollectionDeserializer.deserialize(StringCollectionDeserializer.java:173)
	at com.fasterxml.jackson.databind.deser.std.StringCollectionDeserializer.deserialize(StringCollectionDeserializer.java:21)
	at com.fasterxml.jackson.databind.deser.impl.FieldProperty.deserializeAndSet(FieldProperty.java:138)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:288)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:151)
	at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:286)
	at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:245)
	at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:27)
	at com.fasterxml.jackson.databind.deser.impl.FieldProperty.deserializeAndSet(FieldProperty.java:138)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:288)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:151)
	at com.fasterxml.jackson.databind.deser.impl.FieldProperty.deserializeAndSet(FieldProperty.java:138)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:288)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:151)
	at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4218)
	at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3214)
	at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3182)
	at com.microsoft.azure.PolicyViolation.<init>(PolicyViolation.java:41)

eg: "targetValue":"Microsoft.Resources/subscriptions/resourceGroups" is received instead of "targetValue":["Microsoft.Resources/subscriptions/resourceGroups"]

In this commit:

  • @JsonFormat(with = JsonFormat.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY) is added to ExpressionEvaluationDetails#targetValue
  • verified by adjusting the unit test, which would fail without the fix

…n array

For single values the API might return with a single value instead of an array with one element. In that case the following error is produced:
```
com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.util.ArrayList<java.lang.Object>` out of VALUE_STRING token
 at [Source: (String)"{"policyDefinitionDisplayName":"Allowed resource types","policySetDefinitionDisplayName":"webapp","evaluationDetails":{"evaluatedExpressions":[{"result":"False","expression":"type","path":"type","expressionValue":"Microsoft.ApiManagement/service","targetValue":"Microsoft.Resources/resourceGroups","operator":"In"}]},"policyDefinitionId":"/providers/Microsoft.Authorization/policyDefinitions/a08ec900-254a-4555-9bf5-e42af04b5c5c","policySetDefinitionId":"/providers/Microsoft.Management/managementGro"[truncated 692 chars]; line: 1, column: 262] (through reference chain: com.microsoft.azure.CloudError["additionalInfo"]->java.util.ArrayList[1]->com.microsoft.azure.PolicyViolationErrorInfo["evaluationDetails"]->com.microsoft.azure.EvaluationDetails["evaluatedExpressions"]->java.util.ArrayList[0]->com.microsoft.azure.ExpressionEvaluationDetails["targetValue"])

	at com.fasterxml.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:59)
	at com.fasterxml.jackson.databind.DeserializationContext.reportInputMismatch(DeserializationContext.java:1445)
	at com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1219)
	at com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1129)
	at com.fasterxml.jackson.databind.deser.std.StringCollectionDeserializer.handleNonArray(StringCollectionDeserializer.java:274)
	at com.fasterxml.jackson.databind.deser.std.StringCollectionDeserializer.deserialize(StringCollectionDeserializer.java:183)
	at com.fasterxml.jackson.databind.deser.std.StringCollectionDeserializer.deserialize(StringCollectionDeserializer.java:173)
	at com.fasterxml.jackson.databind.deser.std.StringCollectionDeserializer.deserialize(StringCollectionDeserializer.java:21)
	at com.fasterxml.jackson.databind.deser.impl.FieldProperty.deserializeAndSet(FieldProperty.java:138)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:288)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:151)
	at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:286)
	at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:245)
	at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:27)
	at com.fasterxml.jackson.databind.deser.impl.FieldProperty.deserializeAndSet(FieldProperty.java:138)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:288)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:151)
	at com.fasterxml.jackson.databind.deser.impl.FieldProperty.deserializeAndSet(FieldProperty.java:138)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:288)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:151)
	at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4218)
	at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3214)
	at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3182)
	at com.microsoft.azure.PolicyViolation.<init>(PolicyViolation.java:41)
```
eg: `"targetValue":"Microsoft.Resources/subscriptions/resourceGroups"` is received instead of `"targetValue":["Microsoft.Resources/subscriptions/resourceGroups"]`

In this commit:
- `@JsonFormat(with = JsonFormat.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY)` is added to `ExpressionEvaluationDetails#targetValue`
- verified by adjusting the unit test, which would fail without the fix
@lacikaaa
Copy link
Contributor Author

Fixes: #708

@lacikaaa
Copy link
Contributor Author

lacikaaa commented Mar 1, 2022

@weidongxu-microsoft @jianghaolu could you take a look? it's a pretty small improvement/fix. thanks

@weidongxu-microsoft
Copy link
Member

weidongxu-microsoft commented Mar 1, 2022

@lacikaaa

Thanks for the contribution. I think PR is good.
However the lib is in maintenance mode, and there is no schedule on the next version to be released.
New lib would be here https://azure.github.io/azure-sdk/releases/latest/java.html

@srnagar for awareness.

@weidongxu-microsoft weidongxu-microsoft merged commit f8889a7 into Azure:master Mar 2, 2022
@lacikaaa lacikaaa deleted the tgval branch March 7, 2022 10:27
@lacikaaa
Copy link
Contributor Author

lacikaaa commented Mar 8, 2022

thanks for the merge and information @weidongxu-microsoft

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

Successfully merging this pull request may close these issues.

2 participants