Skip to content

Software Development at Program Tom LTD

Place for coding, programming, development and software in general.

Menu
  • Blog
  • PDF Booklets
  • Dev Utils & Content
  • Java Spring Boot Or Web Apps
  • English
    • български
    • English
    • Español
    • Português
    • हिन्दी
    • Русский
    • Deutsch
    • Français
    • Italiano
    • العربية
  • About Us
Menu
List with IDs between Dart & Java

List with IDs between Dart & Java

Posted on May 22, 2025 by Toma Velev

To send List of IDs – a List<UUID> (orList<String> in Dart format) – to a Java Spring Boot backend as a @RequestBody, using Dart with Retrofit annotations, you can proceed like this:


✅ Spring Boot Backend (Example)

Your controller might look like:

@PostMapping("/uuids")
public ResponseEntity<Void> receiveUuids(@RequestBody List<UUID> uuids) {
    System.out.println("Received UUIDs: " + uuids);
    return ResponseEntity.ok().build();
}

Spring will automatically convert the incoming JSON array of UUID strings to a List<UUID>.


✅ Dart Retrofit Setup

Here’s how to send it using Retrofit in Dart:

1. Retrofit Interface

import 'package:retrofit/retrofit.dart';
import 'package:dio/dio.dart';

part 'your_api_client.g.dart';

@RestApi(baseUrl: "http://your.api.url")
abstract class YourApiClient {
  factory YourApiClient(Dio dio, {String baseUrl}) = _YourApiClient;

  @POST("/uuids")
  Future<void> sendUuids(@Body() List<String> uuids);
}

2. Sending UUIDs

final dio = Dio();
final client = YourApiClient(dio);

final uuidList = [
  "550e8400-e29b-41d4-a716-446655440000",
  "123e4567-e89b-12d3-a456-426614174000"
];

await client.sendUuids(uuidList);

✅ Notes

  • Dart UUIDs are typically handled as strings when serializing to JSON.
  • If you’re using the uuid package in Dart, just use .toString() to get valid string representations.
  • Ensure your Content-Type header is application/json (Dio does this by default).

How to do this manually: Ensure your Content-Type header is application/json (Dio does this by default).

 

✅ Best Way to Set Content-Type: application/json in Dart Retrofit

Since Dio handles application/json automatically when using @Body() with JSON-serializable types (like List<String>), you usually don’t need to set it.

However, to do it manually, here are your options:


✅ Option 1: Set globally on Dio

final dio = Dio(BaseOptions(
  baseUrl: "http://your.api.url",
  headers: {
    "Content-Type": "application/json",
  },
));

final client = YourApiClient(dio);

✅ Option 2: Set dynamically with @Header()

If you want to control it per call:

Retrofit API definition:

@POST("/uuids")
Future<void> sendUuids(
  @Header("Content-Type") String contentType,
  @Body() List<String> uuids,
);

Calling it:

await client.sendUuids("application/json", uuidList);

✅ Option 3: Dio interceptor (for advanced control)

You can also use an interceptor to force application/json if needed for all or specific requests.

dio.interceptors.add(InterceptorsWrapper(
  onRequest: (options, handler) {
    options.headers["Content-Type"] = "application/json";
    return handler.next(options);
  },
));

Here is more about Universal IDs in Flutter : https://programtom.com/dev/2023/07/13/what-flutter-packages-what-could-i-use-for-unique-device-identifier/

  • Prompt-to-Production: How AI is Forcing Us to Build Higher Quality Software
  • Debug Web View Flutter App
  • Skipping AI? You’re a Relic – Time to Evolve or Perish!
  • 2026 Flutter Launch Blueprint: Your 10-Step Checklist to App Store Domination
  • Product Requirements Document – for different software development levels

Categories

  • Apps (25)
  • ChatGPT (27)
  • Choosing a Framework (38)
  • Flutter (281)
  • Graphical User Interface (14)
  • Marketing (119)
  • Software Development (292)
  • Spring (45)
  • StartUp (22)
  • Uncategorized (14)
  • Uncategorized (4)
  • Vaadin (16)

Tags

Algorithms (9) crypto (29) flutterdev (39) General (86) Java (7) QR & Bar Codes (3) Software Dev Choices (33) Spring Boot (1) standards (1) Theme (3) User Authentication & Authorization (9) User Experience (10) Utilities (19) WordPress (11)

Product categories

  • All Technologies (87)
    • Flutter Apps (26)
    • GPT (4)
    • Java (39)
    • Native Android (3)
    • PHP (9)
    • Spring (Boot) / Quarkus (36)
    • Utils (15)
    • Vaadin 24+ (28)
    • Vaadin 8 (1)
  • Apps (18)
    • Employees DB (1)
    • Notes (6)
    • Personal Budget (1)
    • Recipes Book (1)
    • Stuff Organizer (1)
    • To-Do (2)
  • PDF Books (3)
  • Source Code Generators (8)

Recent Posts

  • Prompt-to-Production: How AI is Forcing Us to Build Higher Quality Software
  • Debug Web View Flutter App
  • Skipping AI? You’re a Relic – Time to Evolve or Perish!
  • 2026 Flutter Launch Blueprint: Your 10-Step Checklist to App Store Domination
  • Product Requirements Document – for different software development levels

Post Categories

  • Apps (25)
  • ChatGPT (27)
  • Choosing a Framework (38)
  • Flutter (281)
  • Graphical User Interface (14)
  • Marketing (119)
  • Software Development (292)
  • Spring (45)
  • StartUp (22)
  • Uncategorized (14)
  • Uncategorized (4)
  • Vaadin (16)