<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: [JSON; MongoDB; java mongodb driver] Data type issue (bigDecimal and date/datetime) in Talend Studio</title>
    <link>https://community.qlik.com/t5/Talend-Studio/JSON-MongoDB-java-mongodb-driver-Data-type-issue-bigDecimal-and/m-p/2291848#M64984</link>
    <description>&lt;P&gt;Hmmm. &lt;/P&gt;&lt;P&gt;Thanks for that. Do you know how to write in JSON file (I'm using jackson library) &lt;B&gt;NumberDecimal(&lt;/B&gt;something&lt;B&gt;) &lt;/B&gt;?&lt;/P&gt;&lt;P&gt;I can write only boolean (true, false), strings (eclosed by double quotes), numbers, JSON objects and arrays and null.&lt;/P&gt;</description>
    <pubDate>Tue, 15 Mar 2022 17:10:13 GMT</pubDate>
    <dc:creator>JackStrong</dc:creator>
    <dc:date>2022-03-15T17:10:13Z</dc:date>
    <item>
      <title>[JSON; MongoDB; java mongodb driver] Data type issue (bigDecimal and date/datetime)</title>
      <link>https://community.qlik.com/t5/Talend-Studio/JSON-MongoDB-java-mongodb-driver-Data-type-issue-bigDecimal-and/m-p/2291846#M64982</link>
      <description>&lt;P&gt;Hi All.&lt;/P&gt;&lt;P&gt;I'm loading the JSON files to MongoDB using mongo-java-driver-3.12.7.jar library .&lt;/P&gt;&lt;P&gt;Almost everything is ok but there is an issue regarding data types.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;P&gt;Currently when I have big decimal value in the file (let say 1234567890123456&lt;B&gt;789.1234567&lt;/B&gt;), after loading to Mongo the data type is not Decimal128 (means big decimal) but it is Double. It causes that the value in MongoDB looks like this 1234567890123456&lt;B&gt;800&lt;/B&gt;.&lt;/P&gt;&lt;P&gt;Probably the issue is because I'm using Document class (import org.bson.Document).&lt;/P&gt;&lt;P&gt;How to force MongoDB to write big decimal value as Decimal128?&lt;/P&gt;&lt;P&gt;I tried to change Document to BsonDocument (import org.bson.BsonDocument) but I got stuck because I'm not able to call getCollection method without errors.&lt;/P&gt;&lt;P&gt;For Document there is no error message when I call (but there is data type issue):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;MongoCollection&amp;lt;Document&amp;gt; collection = database.getCollection(context.collection_name);&lt;/P&gt;&lt;P&gt;For BsonDocument I'm trying to call getCollection but without success (method overloading):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;MongoCollection&amp;lt;BsonDocument&amp;gt; collection = database.getCollection(context.collection_name, &lt;B&gt;java.lang.Class&amp;lt;TDocument&amp;gt; documentClass&lt;/B&gt;);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper" image-alt="0695b00000PKcJ3AAL.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/139586i2996AD41EEA8EDEE/image-size/large?v=v2&amp;amp;px=999" role="button" title="0695b00000PKcJ3AAL.png" alt="0695b00000PKcJ3AAL.png" /&gt;&lt;/span&gt;What should I put instead of &lt;B&gt;java.lang.Class&amp;lt;TDocument&amp;gt; documentClass &lt;/B&gt;?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2 &lt;/P&gt;&lt;P&gt;Similar (but different) case for date/datetime values. &lt;/P&gt;&lt;P&gt;Is there any way to force MongoDB to write and store date/datetime values as Date data type?&lt;/P&gt;&lt;P&gt;I'm asking because whenever I load the data to Mongo date and datetime values are stored as strings (there is no date/datetime type in JSON).&lt;/P&gt;&lt;P&gt;To be honest I found the way how to do that in case of org.bson.Document class:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;DateFormat formatterDateTime = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;Date dateOrderDateTime = formatterDateTime.parse(doc.getString("orderDateTime"));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;doc.append("orderDateTime", dateOrderDateTime);  &lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but this approach requires to know what are the field names (keys). I have one big generic job which is responsible for processing more less fifty different json files (each file has a different schema) and I need to store the date/datetime values as Date in MongoDB for all of the date/datetime fields/keys regardless of the name.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;JackStrong&lt;/P&gt;</description>
      <pubDate>Tue, 15 Mar 2022 13:11:06 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/JSON-MongoDB-java-mongodb-driver-Data-type-issue-bigDecimal-and/m-p/2291846#M64982</guid>
      <dc:creator>JackStrong</dc:creator>
      <dc:date>2022-03-15T13:11:06Z</dc:date>
    </item>
    <item>
      <title>Re: [JSON; MongoDB; java mongodb driver] Data type issue (bigDecimal and date/datetime)</title>
      <link>https://community.qlik.com/t5/Talend-Studio/JSON-MongoDB-java-mongodb-driver-Data-type-issue-bigDecimal-and/m-p/2291847#M64983</link>
      <description>&lt;P&gt;Hi for decimal maybe you have to something like this in your json :&lt;/P&gt;&lt;P&gt;{ "totalValue" : NumberDecimal("100.0005") }&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Mar 2022 14:35:28 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/JSON-MongoDB-java-mongodb-driver-Data-type-issue-bigDecimal-and/m-p/2291847#M64983</guid>
      <dc:creator>gjeremy1617088143</dc:creator>
      <dc:date>2022-03-15T14:35:28Z</dc:date>
    </item>
    <item>
      <title>Re: [JSON; MongoDB; java mongodb driver] Data type issue (bigDecimal and date/datetime)</title>
      <link>https://community.qlik.com/t5/Talend-Studio/JSON-MongoDB-java-mongodb-driver-Data-type-issue-bigDecimal-and/m-p/2291848#M64984</link>
      <description>&lt;P&gt;Hmmm. &lt;/P&gt;&lt;P&gt;Thanks for that. Do you know how to write in JSON file (I'm using jackson library) &lt;B&gt;NumberDecimal(&lt;/B&gt;something&lt;B&gt;) &lt;/B&gt;?&lt;/P&gt;&lt;P&gt;I can write only boolean (true, false), strings (eclosed by double quotes), numbers, JSON objects and arrays and null.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Mar 2022 17:10:13 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/JSON-MongoDB-java-mongodb-driver-Data-type-issue-bigDecimal-and/m-p/2291848#M64984</guid>
      <dc:creator>JackStrong</dc:creator>
      <dc:date>2022-03-15T17:10:13Z</dc:date>
    </item>
    <item>
      <title>Re: [JSON; MongoDB; java mongodb driver] Data type issue (bigDecimal and date/datetime)</title>
      <link>https://community.qlik.com/t5/Talend-Studio/JSON-MongoDB-java-mongodb-driver-Data-type-issue-bigDecimal-and/m-p/2291849#M64985</link>
      <description>&lt;P&gt;Wich version of Jackson library?&lt;/P&gt;</description>
      <pubDate>Tue, 15 Mar 2022 19:29:06 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/JSON-MongoDB-java-mongodb-driver-Data-type-issue-bigDecimal-and/m-p/2291849#M64985</guid>
      <dc:creator>gjeremy1617088143</dc:creator>
      <dc:date>2022-03-15T19:29:06Z</dc:date>
    </item>
    <item>
      <title>Re: [JSON; MongoDB; java mongodb driver] Data type issue (bigDecimal and date/datetime)</title>
      <link>https://community.qlik.com/t5/Talend-Studio/JSON-MongoDB-java-mongodb-driver-Data-type-issue-bigDecimal-and/m-p/2291850#M64986</link>
      <description>&lt;P&gt;below 2.9.10 you could as this to your Mapper :&lt;/P&gt;&lt;P&gt;mapper.configure(Feature.WRITE_BIGDECIMAL_AS_PLAIN, true);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;else &lt;/P&gt;&lt;P&gt;mapper.enable(JsonGenerator.Feature.WRITE_BIGDECIMAL_AS_PLAIN);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Mar 2022 19:36:54 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/JSON-MongoDB-java-mongodb-driver-Data-type-issue-bigDecimal-and/m-p/2291850#M64986</guid>
      <dc:creator>gjeremy1617088143</dc:creator>
      <dc:date>2022-03-15T19:36:54Z</dc:date>
    </item>
    <item>
      <title>Re: [JSON; MongoDB; java mongodb driver] Data type issue (bigDecimal and date/datetime)</title>
      <link>https://community.qlik.com/t5/Talend-Studio/JSON-MongoDB-java-mongodb-driver-Data-type-issue-bigDecimal-and/m-p/2291851#M64987</link>
      <description>&lt;P&gt;Hi @guenneguez jeremy​&amp;nbsp;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I see you have a big knowledge regarding java and JSON. Thank you for all your replies.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Unfortunately,  till now I'm not able to achieve what I want.&lt;/P&gt;&lt;P&gt;In my case the whole scenario looks like this: &lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Pick up the JSON file (array of documents) and split into multiple files (one file one document). Split files are located in Talend job server.  (JSON deserialization and serialization)&lt;/LI&gt;&lt;LI&gt;Then pick up split files one by one and load the documents to MongoDB. (JSON deserialization)&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Once step 1. is completed I should have correct JSON files in Talens server. &lt;/P&gt;&lt;P&gt;As I know { "totalValue" : &lt;B&gt;NumberDecimal&lt;/B&gt;("100.0005") } is not correct JSON (because "NumberDecimal(" and ")" strings).&lt;/P&gt;&lt;P&gt;And to be honest right know I am able to create correct JSON split files in Talend server even if they contain big decimal values. Probably this is because source JSON file contains big decimals as strings so it is enough to read them as strings and then put new BigDecimal("100.0005") constructor. It works. I have correct JSON split files. Step 1 completed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But loading the JSON files to MongoDB (step 2) is challenging. &lt;/P&gt;&lt;P&gt;Using java mongodb driver and: &lt;/P&gt;&lt;P&gt;a) MongoCollection&amp;lt;Document&amp;gt;collection = database.getCollection(collection_name);&lt;/P&gt;&lt;P&gt;It doesn't work because big decimal values from JSON file are treated as Double. &lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;b) MongoCollection&amp;lt;BsonDocument&amp;gt;collection = database.getCollection(collection_name, &lt;B&gt;java.lang.Class&amp;lt;TDocument&amp;gt; documentClass&lt;/B&gt;);&lt;/P&gt;&lt;P&gt;It throws exception because I don't know what should be put instead of text in bold. &lt;/P&gt;&lt;P&gt;To be honest I'm not sure if this approach will work. I was not able to run the job even once because exception.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Mar 2022 11:34:11 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/JSON-MongoDB-java-mongodb-driver-Data-type-issue-bigDecimal-and/m-p/2291851#M64987</guid>
      <dc:creator>JackStrong</dc:creator>
      <dc:date>2022-03-16T11:34:11Z</dc:date>
    </item>
    <item>
      <title>Re: [JSON; MongoDB; java mongodb driver] Data type issue (bigDecimal and date/datetime)</title>
      <link>https://community.qlik.com/t5/Talend-Studio/JSON-MongoDB-java-mongodb-driver-Data-type-issue-bigDecimal-and/m-p/2291852#M64988</link>
      <description>&lt;P&gt;&lt;B&gt;NumberDecimal&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;I&gt;New&amp;nbsp;in version&amp;nbsp;3.4&lt;/I&gt;.&lt;/P&gt;&lt;P&gt;The&amp;nbsp;&lt;A href="https://docs.mongodb.com/manual/reference/program/mongo/#mongodb-binary-bin.mongo" alt="https://docs.mongodb.com/manual/reference/program/mongo/#mongodb-binary-bin.mongo" target="_blank"&gt;mongo&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;shell treats all numbers as 64-bit floating-point&amp;nbsp;&lt;/P&gt;&lt;P&gt;double&lt;/P&gt;&lt;P&gt;&amp;nbsp;values by default. The&amp;nbsp;&lt;A href="https://docs.mongodb.com/manual/reference/program/mongo/#mongodb-binary-bin.mongo" alt="https://docs.mongodb.com/manual/reference/program/mongo/#mongodb-binary-bin.mongo" target="_blank"&gt;mongo&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;shell provides the&lt;/P&gt;&lt;P&gt;NumberDecimal()&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;constructor to explicitly specify 128-bit decimal-based floating-point values capable of emulating decimal rounding with exact precision. This functionality is intended for applications that handle&amp;nbsp;&lt;A href="https://docs.mongodb.com/manual/tutorial/model-monetary-data/" alt="https://docs.mongodb.com/manual/tutorial/model-monetary-data/" target="_blank"&gt;monetary data&lt;/A&gt;, such as financial, tax, and scientific computations.&lt;/P&gt;&lt;P&gt;The&amp;nbsp;&lt;/P&gt;&lt;P&gt;decimal&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;A href="https://docs.mongodb.com/manual/reference/bson-types/" alt="https://docs.mongodb.com/manual/reference/bson-types/" target="_blank"&gt;BSON type&lt;/A&gt;&amp;nbsp;uses the IEEE 754 decimal128 floating-point numbering format which supports 34 decimal digits (i.e. significant digits) and an exponent range of −6143 to +6144.&lt;/P&gt;&lt;P&gt;The&amp;nbsp;&lt;/P&gt;&lt;P&gt;NumberDecimal()&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;constructor accepts the&amp;nbsp;&lt;/P&gt;&lt;P&gt;decimal&lt;/P&gt;&lt;P&gt;&amp;nbsp;value as a string:&lt;/P&gt;&lt;P&gt;NumberDecimal("1000.55")&lt;/P&gt;</description>
      <pubDate>Wed, 16 Mar 2022 12:38:10 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/JSON-MongoDB-java-mongodb-driver-Data-type-issue-bigDecimal-and/m-p/2291852#M64988</guid>
      <dc:creator>gjeremy1617088143</dc:creator>
      <dc:date>2022-03-16T12:38:10Z</dc:date>
    </item>
  </channel>
</rss>

