We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Issue with JsonDataSource and XmlDataSource auto formatting, unable to turn it off

Currently we are having an issue with JsonDataSource and XmlDataSource where Aspose is trying to do number / date formatting on String data.

We need a way to stop Aspose from trying to format this data because it is making mistakes in multiple areas:

Telephone numbers: +99999 becomes 99999
Zip Codes: 1000-01 becomes 1st January 1000 !!
Preformatted dates: converted to ‘date’ type requiring the template to format the dates.

What is the way to tell JsonDataSource and XmlDataSource to treat the data as String and not to do any formatting on it?

We have an aspose.total licence and are using aspose: 20.9-jdk17

We cannot change the logic of Aspose via class extension and overriding because the internal classes are obfuscated on each jar download.

1 Like

@robert.issa.turnbull.elca In your case you should use JsonSimpleValueParseMode.STRICT in JsonDataLoadOptions.SimpleValueParseMode. For example, in this mode the type of ‘prop’ from the JSON snippet { prop: "123" } is determined as string in this mode.
For date values you can specify JsonDataLoadOptions.ExactDateTimeParseFormats property to specify date time values parsing formats.

Thanks!

How about for XmlDataSource ? there does not seem to have a XmlDataLoadOptions in aspose 20.9-jdk17

@robert.issa.turnbull.elca The latest version of Aspose.Words does have XmlDataLoadOptions, but there are not similar options to control parsing values like in JSON.

However, when you use XmlDataSource you can use XML schema.

When XML Schema Definition is passed to a constructor of this class, data types of values of simple XML elements and attributes are determined according to the schema. So in template documents, you can work with typed values rather than just strings.

When XML Schema Definition is not passed to a constructor of this class, data types of values of simple XML elements and attributes are determined automatically upon their string representations.

1 Like

Thanks again!

Last question, is there a IMailMerge version of the Json Loader?

@robert.issa.turnbull.elca No, unfortunately, there is no direct way to use Json data in Mail Merge. In this case you should implement your own IMailMergeDataSource.

Thanks for the fast support!

1 Like