Convert a delta table (flattened json format) to a nested java object
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2025 10:48 AM
I have a delta table with columns like below format. I am querying Databricks using databricks-jdbc 2.7.1 driver. I want to convert the result set to a nested java object.
Order_actualPickupAddress_residential -> string
Order_pickupRequestDetails -> array<struct<pickupRequestOccurenceNumber:string,payorContact:struct<personName:string,companyName:string,phoneNumber:string>,pickupAddress:struct<classification:string,streetLines:array<string>,city:string,stateOrProvinceCode:string,postalCode:string,countryCode:string,residential:string>,softwareId:string,softwareVersion:string,deviceType:string,serviceOfferingId:string,primaryOrderConfirmationIdDetails:array<struct<id:string,type:string>>,requestReceivedDateTime:string,pickupDetailsByDay:array<struct<expectedDate:string,performingOpCo:string,expectedDateTimeWindow:struct<startDateTime:string,endDateTime:string>,attemptEngagementWindow:struct<startDateTime:string,endDateTime:string>,attemptOutcome:string>>>>
I have a java object "Order" which has an object "pickupRequestDetails" which internally have "payorContact" object. what is an easy way to map 100s of such nested fields?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2025 06:57 AM
Here are some suggestions/ideas to consider:
Order object described, consider the following approaches:ObjectMapper to map it directly to your desired Java class structure. - Parse the result set: java
ObjectMapper objectMapper = new ObjectMapper();
Order order = objectMapper.readValue(resultSetJson, Order.class);
- Configure annotations on your Java classes, e.g., @JsonProperty for specific mappings.sql
SELECT to_json(struct(*)) AS json_data FROM delta_table
This returns each row as JSON, which makes mapping straightforward.databricks-jdbc compatibility to retrieve complex structures like arrays of structs. Libraries such as Arrow (when enabled) simplify serialization but might require configurations like disabling EnableArrow for better UTF-8 handling. - Nested structs (e.g., struct<pickupRequestOccurenceNumber: string, ...>) must align with the Java class definition.