dynamo_json_decoder
A lightweight, high-performance utility for decoding serialized JSON text into Dart objects (Map or List). Designed for speed and ease of use in Flutter applications.
🌟 Features
- Type-Safe Decoding: Easily convert raw JSON strings into
Map<String, dynamic>orList<dynamic>. - Debug Logging: Integrated support for error tracking during the decoding process.
- Zero Boilerplate: Static methods allow you to decode without instantiating complex classes.
📦 Installation
Add the dependency to your pubspec.yaml:
dependencies:
dynamo_json_decoder: ^1.0.0
Or run:
flutter pub add dynamo_json_decoder
🚀 Usage
Import the library
import 'package:dynamo_json_decoder/dynamo_decoder.dart';
Simple Decoding Example
void fetchUser() async {
String rawJson = '{"id": 1, "name": "John Doe"}';
// Decode into a Map
Map<String, dynamic> user = DynamoDecoder.decode(rawJson);
print(user['name']); // Output: John Doe
}
Integration with HTTP
import 'package:http/http.dart' as http;
class CustomerDTO {
int? customerID = 0;
String? customerName = "";
String? customerPhone = "";
CustomerDTO({
this.customerID,
this.customerName,
this.customerPhone,
});
CustomerDTO.init(){
customerID = 0;
customerName = "";
customerPhone = "";
}
CustomerDTO fromMap(Map<String, dynamic> json) =>
new CustomerDTO(
customerID: json["customerID"],
customerName: json["customerName"],
customerPhone: json["customerPhone"],
);
}
Future<CustomerDTO> getRemoteDataByID(int customerID) async {
final response = await http.get(
Uri.parse("https://api.example.com/data?customerID=${customerID}"));
if (response.statusCode == 200) {
// Automatically handles Maps
return CustomerDTO.init().fromMap(DynamoDecoder.decode(response.body));
}
}
Future<List<CustomerDTO>> getRemoteListData() async {
List<CustomerDTO> customerList = [];
final response = await http.get(
Uri.parse("https://api.example.com/datalist"));
if (response.statusCode == 200) {
// Automatically handles Lists
List<dynamic> entityMapList = DynamoDecoder.decode(response.body);
entityMapList.forEach((element) {
CustomerDTO customer = CustomerDTO.init().fromMap(element);
customerList.add(customer);
});
}
return customerList;
}
🛠️ Debug Mode
You can pass a reviver function or enable debug logging to inspect the decoding process:
Map<String, dynamic>? jsonObject = DynamoDecoder
.decode(rawJson, debugMode: true, reviver: (k, v) {
print('+++++++++++++++++++++++++++++ k, v ==>> ${k}, ${v}');
});
📄 License
This project is licensed under the Apache 2.0 License - see the LICENSE file for details.
🤝 Contributing
Contributions, issues, and feature requests are welcome! Feel free to check the issues page.
Libraries
- dynamo/project/commons/constants/pad_direction_type
- dynamo/project/commons/system/entities/log_level
- dynamo/project/commons/system/handlers/app_logger
- dynamo/project/commons/system/handlers/dynamo_commons
- dynamo/project/commons/system/handlers/dynamo_decoder
- dynamo/project/commons/system/handlers/token_expected_exception
- dynamo_decoder
- main