Skip to content

Releases: americanexpress/unify-jdocs

unify-jdocs-1.7.1

05 Nov 23:20
Compare
Choose a tag to compare

This is a minor release which contains the following:

  1. A fix to suppress the validation of a field being read if the path / field are not present in the document.
  2. Minor updates to the test suite.

unify-jdocs-1.7.0

15 Feb 20:14
Compare
Choose a tag to compare

Well, this is a fix to a day zero issue. We came across this as an incident in our internal system where we are using JDocs and so posting a fix for the community asap.

How do you know if you are impacted?

Let's say you are using name value pair in the getXXX and setXXX methods and using % so that the value comes from the variable arguments passed to the method but forget to specify the variable arguments like below:

d.getString("$.names[number=%].first_name"); // instead of d.getString("$.names[number=%].first_name", "Some Name");

The above will return null instead of throwing an exception. This is now fixed to throw an exception. Note that this was only happening if name value pairs were being used. If you were using [%] then you are not impacted.

I realize that this may break some running code and so the minor version upgrade.

There is a simple way to scan your code base to see if you have any such occurrences. You can use regular expressions to search for any occurrence of % that lies between [ and ] and ends with ). I used the following pattern to narrow down the list and confirm:

[.%.])

Based on comments, I can also look to release a version that can provide for an option to throw an exception or not in such cases (will be deprecated in the future) but really, I would not like to do this - it is better to fail fast, fix and move on rather than defer to the future.

Test suite is also updated.

unify-jdocs-1.6.0

05 Feb 23:46
Compare
Choose a tag to compare

This is a minor upgrade and tackles the design of the validation framework. In the earlier versions, we had provided two validation options - validate all data paths in the document against the model or validate at read write only. Read write here means the getXXX and setXXX methods which are used to read and write paths / content. When validate on read write was set to true, the validations were performed only on the paths being read or written. In this scenario, it was not possible to be able to validate the document upfront against the model only for the paths which were present in the model (and ignoring the ones that were not).

To take care of this and to provide flexibility, we have introduced an enum known as validation type. This enum can take three values - first value specifies that full validation needs to be done i.e. all data paths need to be validated against model. Second enum specifies that only model paths found in the document should be validated. And third specifies that validation should only be done at read or write (same as before). The usage of this new validation framework has been updated in the documentation under the heading "Validating typed documents".

As a result of the above, certain methods have been deprecated and new ones added. These methods are marked as such in the code. To summarize, the following methods are deprecated:

public static void init(boolean defaultValidateAtReadWriteOnly)
public boolean getDefaultValidateAtReadWriteOnly()
public JDocument(String type, String json, boolean validateAtReadWriteOnly)
public void setType(String type, boolean validateAtReadWriteOnly)
public final void validate(String type)

The following new methods are provided to be used in place of the deprecated ones. The one to use instead of the deprecated ones have also been specified in the comments in the code:

public static void init(CONSTS_JDOCS.VALIDATION_TYPE validationType)
public static CONSTS_JDOCS.VALIDATION_TYPE getDefaultValidationType()
public CONSTS_JDOCS.VALIDATION_TYPE getValidationType()
public JDocument(String type, String json, CONSTS_JDOCS.VALIDATION_TYPE validationType)
public void setType(String type, CONSTS_JDOCS.VALIDATION_TYPE validationType)
public void validateAllPaths(String type)
public void validateModelPaths(String type)

For details on what has been changed, please refer to the PR #12.

The Jackson version has been bumped up to 2.16.1.

Test cases have been updated.

Documentation has been updated.

unify-jdocs-1.5.0

22 Aug 19:24
Compare
Choose a tag to compare

IMPORTANT -> Please read carefully as this release may break running code in one specific scenario.

In March of this year, we had released a version of unify-jdocs which provided the "validate at read write only" feature. What this feature did was that if set to true, it would validate the document against the model only when reading or writing from the document. Unfortunately, the regex validations for values being read had gotten missed out which this release fixes. So, if you have not used this feature i.e. have not ever set validate at read write only to true either while initializing JDocs or while creating a typed document / setting the type of a document, then you are good meaning that you are not impacted.

If, however, you have used this feature and if you have regex validations defined and you read that path from the document, then the regex validations would not have fired. If now you upgrade to this release, you will need to make sure that the paths in the typed documents that you read and the corresponding regex in the model document are in sync else an exception would be thrown.

In addition to fixing above, the set type method also now throws an exception in the following two situations:

  1. An empty string is provided for type field
  2. The document is already a typed document and the type being set is different from the existing type

Please raise issues and I am happy to help. Thanks.

unify-jdocs-1.4.1

15 Aug 19:07
Compare
Choose a tag to compare

Fixed an edge case scenario where path exists API was failing for a JSON document where the root node is an array and if the path being searched was an array that did not exist in the document.

unify-jdocs-1.4.0

07 Jun 19:52
Compare
Choose a tag to compare

Added utility methods added to base package.
Updated documentation.
Added new feature to specify default value for validate at read-write only.
Added new feature to ignore regex if the value for a string data type is empty. Default is false.
Added new feature to allow a date field to be empty string value. Default is true.