Skip to content

io microsphere lang model util JSONAnnotationValueVisitor

github-actions[bot] edited this page Mar 21, 2026 · 1 revision

JSONAnnotationValueVisitor

Type: Class | Module: microsphere-lang-model | Package: io.microsphere.lang.model.util | Since: 1.0.0

Source: microsphere-lang-model/src/main/java/io/microsphere/lang/model/util/JSONAnnotationValueVisitor.java

Overview

A visitor implementation for converting AnnotationValue objects into JSON-formatted strings. This class extends SimpleAnnotationValueVisitor6 and is designed to work with Java annotation processing tools to generate JSON representations of annotation values.

Example Usage

`// Example 1: Visiting a simple annotation value
AnnotationValue value = ...; // e.g., a String, int, or boolean value
ExecutableElement method = ...; // the method corresponding to the annotation attribute
StringBuilder jsonBuilder = new StringBuilder();
JSONAnnotationValueVisitor visitor = new JSONAnnotationValueVisitor(jsonBuilder);
visitor.visit(value, method); // Result: appends JSON key-value pair to jsonBuilder

// Example 2: Visiting an array annotation value
List arrayValues = ...; // list of annotation values
visitor.visitArray(arrayValues, method); // Result: appends JSON array to jsonBuilder

// Example 3: Visiting a nested annotation
AnnotationMirror annotationMirror = ...;
visitor.visitAnnotation(annotationMirror, method); // Result: appends JSON object to jsonBuilder
`

This visitor is typically used during annotation processing to serialize annotation values into a structured JSON format, useful for configuration or metadata generation purposes.

Declaration

public class JSONAnnotationValueVisitor extends SimpleAnnotationValueVisitor6<StringBuilder, ExecutableElement>

Author: Mercy

Version Information

  • Introduced in: 1.0.0
  • Current Project Version: 0.1.10-SNAPSHOT

Version Compatibility

This component is tested and compatible with the following Java versions:

Java Version Status
Java 8 ✅ Compatible
Java 11 ✅ Compatible
Java 17 ✅ Compatible
Java 21 ✅ Compatible
Java 25 ✅ Compatible

Examples

// Example 1: Visiting a simple annotation value
AnnotationValue value = ...; // e.g., a String, int, or boolean value
ExecutableElement method = ...; // the method corresponding to the annotation attribute
StringBuilder jsonBuilder = new StringBuilder();
JSONAnnotationValueVisitor visitor = new JSONAnnotationValueVisitor(jsonBuilder);
visitor.visit(value, method); // Result: appends JSON key-value pair to jsonBuilder

// Example 2: Visiting an array annotation value
List<? extends AnnotationValue> arrayValues = ...; // list of annotation values
visitor.visitArray(arrayValues, method); // Result: appends JSON array to jsonBuilder

// Example 3: Visiting a nested annotation
AnnotationMirror annotationMirror = ...;
visitor.visitAnnotation(annotationMirror, method); // Result: appends JSON object to jsonBuilder

Usage

Maven Dependency

Add the following dependency to your pom.xml:

<dependency>
    <groupId>io.github.microsphere-projects</groupId>
    <artifactId>microsphere-lang-model</artifactId>
    <version>${microsphere-java.version}</version>
</dependency>

Tip: Use the BOM (microsphere-java-dependencies) for consistent version management. See the Getting Started guide.

Import

import io.microsphere.lang.model.util.JSONAnnotationValueVisitor;

API Reference

Public Methods

Method Description
visitBoolean
visitByte
visitChar
visitDouble
visitFloat
visitInt
visitLong
visitShort
visitString
visitType
visitEnumConstant
visitAnnotation
visitArray
visitUnknown

See Also

  • SimpleAnnotationValueVisitor6

This documentation was auto-generated from the source code of microsphere-java.

Home

java-annotations

java-core

jdk-tools

lang-model

annotation-processor

java-test

Clone this wiki locally