Skip to content

πŸ”„ lombokToJson converts Lombok-generated toString() output from ♨️ classes into JSON format for easy integration and debugging.

License

Notifications You must be signed in to change notification settings

sarkarshuvojit/lomboktojson

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

83 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

LombokToJson

A lightweight utility that converts Lombok's default toString() output format to standard JSON format.

Run tests Go Reference Static Badge

Conversion Example

Website

Try the interactive converter at shuvojit.dev/lomboktojson:

Website Screenshot

Installation

CLI Tool

Install the command-line interface tool:

go install github.com/sarkarshuvojit/lomboktojson/cmd/l2j@latest

Usage

As a Go Package

l2j "github.com/sarkarshuvojit/lomboktojson/pkg"


// Convert a Lombok toString string to JSON
lombokStr := "Customer(name=Raju,[email protected],age=15)"
jsonStr, err := l2j.LombokToJson(lombokStr)

// Result: {"name":"Raju","email":"[email protected]","age":15}

CLI Usage

The CLI tool offers three ways to provide input:

1. Interactive Mode

Simply run the tool without any arguments and paste or type your Lombok output. Press Ctrl+D when finished.

l2j > $(dirseq)-customer-data.json
# Paste your Lombok output and press Ctrl+D
# Creates: 1-customer-data.json with the JSON result

2. File Input

Use the -i flag to specify an input file:

l2j -i lombok-output.log > $(dirseq)-parsed-output.json
# Creates: 1-parsed-output.json with the JSON result

3. Pipe Input

Pipe content directly into the tool:

cat lombok-output.log | l2j > $(dirseq)-customer-records.json
# Creates: 1-customer-records.json with the JSON result

4. Convert a file line by line from Lombok to Json into a diff file

$ cat lombokobjects.txt |  xargs -L1 echo | l2j |sed 's/}/}\n/g' > $(dirseq)-jsonobjects.txt
# Reads line by line from a file containing lombok object in each line creating another file with same number of lines containing the json equivalent.

Example Workflow

# Extract logs containing Customer objects
grep "Customer(" application.log > lombok-logs.txt

# Convert to JSON and save to sequentially named file
cat lombok-logs.txt | l2j > $(dirseq)-converted-customers.json
# Creates: 1-converted-customers.json

# Process another batch
grep "Order(" application.log | l2j > $(dirseq)-converted-orders.json
# Creates: 2-converted-orders.json

Note: The examples use dirseq to generate sequential filenames - a helpful utility for organizing outputs chronologically.

Problem

When using Lombok's @ToString or @Data annotations in Java classes, log output is generated in Lombok's specific format:

Customer(name=Raju,[email protected],age=15)

This format isn't easily parseable by standard tools that expect JSON:

{ "name": "Raju", "email": "[email protected]", "age": 15 }

LombokToJson bridges this gap by providing a simple conversion utility.

Features

  • Convert Lombok's toString format to standard JSON
  • Simple API for integration into existing projects
  • No external dependencies
  • High performance parsing
  • Supports nested objects and collections

Testing

Using Go's built-in test tool

# Run tests
go test

# Run tests with verbose output
go test -v ./...

Development with live reload

Prerequisites: Install air

# Run tests automatically on file changes
air

Using Makefile

# Run tests
make test

# Run tests with verbose output
make testv

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

πŸ”„ lombokToJson converts Lombok-generated toString() output from ♨️ classes into JSON format for easy integration and debugging.

Topics

Resources

License

Stars

Watchers

Forks