Skip to content

Add checkstyle rule to validate serialization method completeness#47916

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/add-checkstyle-rule-validation
Draft

Add checkstyle rule to validate serialization method completeness#47916
Copilot wants to merge 3 commits intomainfrom
copilot/add-checkstyle-rule-validation

Conversation

Copy link
Contributor

Copilot AI commented Feb 5, 2026

Enforces that classes implementing JsonSerializable or XmlSerializable provide required serialization methods at compile-time via checkstyle.

Changes

  • SerializableMethodsCheck - New checkstyle rule validating:

    • JsonSerializable implementations have instance toJson() and static fromJson(JsonReader)
    • XmlSerializable implementations have instance toXml() and static fromXml(XmlReader)
  • Configuration - Enabled in all checkstyle configs (track2, clientcore, vnext)

  • Tests - Coverage for missing methods, incorrect modifiers, nested classes, and both interfaces

Example violations caught

// Missing static fromJson - checkstyle error
public class Foo implements JsonSerializable<Foo> {
    @Override
    public JsonWriter toJson(JsonWriter writer) { ... }
    // ERROR: Class implementing JsonSerializable must provide a static fromJson method
}

// Non-static fromJson - checkstyle error  
public class Bar implements JsonSerializable<Bar> {
    @Override
    public JsonWriter toJson(JsonWriter writer) { ... }
    
    public Bar fromJson(JsonReader reader) { ... }  
    // ERROR: Must be static
}
Original prompt

This section details on the original issue you should resolve

<issue_title>[FEATURE REQ] Checkstyle rule to validate serialization methods exist on types that implement JsonSerializable or XmlSerializable</issue_title>
<issue_description>Add a new checkstyle rule to validate the following:

  • classes implementing JsonSerializable (in com.azure.json package) have the toJson and fromJson methods.
  • classes implementing XmlSerializble (in com.azure.xml package) have the toXml and fromXml methods.

All custom checkstyle rules are implemented here - https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/tools/linting-extensions/src/main/java/io/clientcore/linting/extensions/checkstyle/checks

The new checkstyle rule should be implemented in the same package as the rest of the checkstyle rules and should be enabled for all libraries by default.</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits February 5, 2026 21:39
… validation

Co-authored-by: srnagar <51379715+srnagar@users.noreply.github.com>
Co-authored-by: srnagar <51379715+srnagar@users.noreply.github.com>
Copilot AI changed the title [WIP] Add checkstyle rule for serialization methods validation Add checkstyle rule to validate serialization method completeness Feb 5, 2026
Copilot AI requested a review from srnagar February 5, 2026 21:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE REQ] Checkstyle rule to validate serialization methods exist on types that implement JsonSerializable or XmlSerializable

2 participants