Troublesome Behavior Encountered when Exporting Database Table to JSon with Apache Camel

I need to find a way to export data from a database table into a single JSON file. Currently, when I run the code provided below, it splits the data rows into multiple files instead of creating one single file.

This is the Camel's route:

 public void configure() throws Exception {
    JsonDataFormat jsonFormat = new JsonDataFormat(JsonLibrary.XStream);
    jsonFormat.setUnmarshalType(Customer.class);
    from("sql: SELECT * FROM assignment01.staff?dataSourceRef=dataSource")
            .marshal(jsonFormat)
            .to("file:data/test");
}

Below is my XML configuration:

    <bean id="route" class="com.huyqtran.JSonRoute"/>
<camelContext xmlns="http://camel.apache.org/schema/spring">
    <routeBuilder ref="route"/>
</camelContext>
<bean id="dataSource"
      class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
    <property name="url" value="jdbc:mysql://localhost:3306/assignment01?useSSL=false"/>
    <property name="username" value="root"/>
    <property name="password" value=""/>
</bean>

I anticipate that my application will generate just one JSON file containing all the data from the table.

Answer №1

Instruct the Elephant to add to the document with the preference documentExist=Add: , for example

.to("document:data/test?documentExist=Add");

or advise the Database component to fetch the complete result-set by disabling its iterator, for instance useIterator=false

from("database: SELECT * FROM assignment01.personnel?dataSourceRef=dataSource&useIterator=false")

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Undefined Return Value from Node's Exports Function

I have a function that exports data and is supposed to return a JSON array of draft results. However, when I try to access the draft_results variable in the route provided below in app.js, it shows as undefined. app.get('/draft-results', functio ...

Obtaining pictures from a URL with unique characters

protected Bitmap doInBackground(String... params) { Bitmap bitmap = null; try{ URL url = new URL(params[0]); InputStream inputStream = url.openStream(); bitmap = BitmapFactory.decodeStream ...

Having trouble resolving the symbol JSONObject in Android Studio?

After spending two days on this issue, I have encountered a problem with my Android Studio. While I am able to work with other PCs without any issues, my Android Studio is unable to import the necessary library. Here are two screenshots showcasing the prob ...

What is the process of importing a JSON file in JavaScript?

Is there a way to import a JSON file into my HTML form by calling $(document).ready(function (){});? The properties defined in the JSON file are crucial for the functionality of my form. Can anyone guide me on how to achieve this? ...

Which is more suitable for storing data for boardgame session data: redisJSON or traditional redis?

Recently set up a Redis server for my backend using ioredis. I've discovered that if I want to store data in JSON format, I need to use the redisJSON module because hashes are only string typed and flat. However, since I'm only storing one objec ...

The PHP function json_encode seems to be returning a null value

Greetings! I am currently facing an issue with my PHP script while trying to access a database from a Swift application that I'm developing. Everything was going smoothly until I reached a table with multiple rows containing JSON data. This has been c ...

When attempting to set up a build task in VSCODE by clicking the configure button, I encountered an issue where nothing

Whenever I try Ctrl+shift+B, nothing happens. Even after creating a .vscode folder with a tasks.json file inside, VScode still doesn't respond. I'm expecting to see the menus pop up like in other posts, but mine just seems stuck. Any help would b ...

Sending JSON data from an iOS app to a Flask backend

Within my Flask Python web application, I store certain parameters in SessionStorage to later send back to Flask and save this data as a text file. Interestingly, the process functions perfectly on PCs and Android devices but encounters issues on iOS devi ...

Xamarin Refit encountering an issue: Newtonsoft.Json.JsonSerializationException

I'm encountering some hurdles with JSON Serialization. Whenever I attempt to deserialize my JSON Object, it throws the following error : Newtonsoft.Json.JsonSerializationException: Cannot deserialize the current JSON array (e.g. [1,2,3]) into type ...

Reading JSON messages in a request on the server side of a RESTful service: A comprehensive guide

I am having trouble reading JSON data that is being sent from a client to a service. Despite trying multiple methods, the console continues to display an empty object. //Service: My service @Path("signup") public class signupservice { @P ...

The implementation of the necessary cerberus rule is contingent upon specific conditions

I am facing a challenge with a large JSON document, where certain fields need to be mandatory based on the values of other fields. For example: document = {'is_realty_address': False, 'postcode': 111111} In this case, the postcode fie ...

Retrieving JSON information using Angular.js

I have been struggling to fetch JSON data from a URL using the code provided below. Unfortunately, it seems that the data is not being populated as expected. Despite trying various approaches, nothing seems to work out successfully. Below is the basic code ...

Utilizing angularjs ng-repeat directive to present JSON data in an HTML table

I've been struggling to showcase the JSON data in my HTML table using AngularJS ng-repeat directive. Here's the code snippet: <thead> <tr> <th ng-repeat="(header, value) in gridheader">{{value}}</th> </tr> </ ...

What is the best way to update JSON data using JQuery?

I apologize for posing a seemingly simple query, but my understanding of JavaScript and JQuery is still in its early stages. The predicament I currently face involves retrieving JSON data from an external server where the information undergoes frequent ch ...

Converting a JSON image string (not a URL) into a UIImage to display

After spending an entire day trying to solve this, I am really desperate for an answer. It seems like a simple task - I have a JSON array of images in the form of strings (I believe). These are not URLs, but rather image file names like "GoodLogo.png". Typ ...

Using Ext JS to send an AJAX request with a JSON object to an ASP.NET MVC web application

Currently, I am attempting to transmit a json object (extjs client) to an asp.net server-side application: Here is the sample request with logic intact: var orderData = []; for (i = 0; i < checkedList.length; i++) { orderData.push ...

PHP REST API to handle requests and generate corresponding responses

I am currently struggling to find a solution for accurately translating the responses and requests for my PHP REST API. Here is an example of an array that I receive from the API: [{ "id": "49557a36-028b-40c6-b2d8-8095468af130", "startDate": "2020-04- ...

Node.js encountered an abrupt conclusion in the JSON input that was not anticipated

Upon receiving Json data as post data in my node.js server, I encountered an issue with parsing the string. Here is a snippet of my node.js server code: res.header("Access-Control-Allow-Origin", "*"); req.on('data',function(data) { var ...

Looking to query JSON using jQuery - how can I accomplish this?

Currently, I am utilizing session storage to temporarily store data and attempting to search for a specific string (CatalogNumber) within the session data. If the string is not found, my goal is to add it. Despite my efforts, I have encountered issues wit ...

Eliminating backslashes when transforming data in Mule 4 with DataWeave

I'm currently working on a data integration project in Mule 4 where I am retrieving information from an SQL Server Database and converting it into JSON. However, I have encountered an issue where my input contains a single backslash that gets transfor ...