Skip to content

Static fields are included when jsonLibrary=gson  #496

Closed
@blutorange

Description

@blutorange

When jsonLibrary=gson is set, the type declarations for a Java interface includes its static members.

public class Demo {
  public static String THIS_FIELD_SHOULD_NOT_BE_INCLUDED;
  public String thisShouldBeIncluded;
}

results in something like (when generating classes as interfaces)

export interface Demo {
  THIS_FIELD_SHOULD_NOT_BE_INCLUDED: string ;
  thisShouldBeIncluded: string;
}

Unless I'm missing something and this is by design (?), they should not be included, at least not when generating typescript interfaces:

  • The default new Gson().toJson(someObjectImplementingTheInterfaceWithStaticField) does not seem to includde static fields
  • TypeScript does not support static fields in interfaces
  • jsonLibrary=jackson2 for static fields also does not seem to include static fields on interfaces

A quick look at the code in the debugger seems like a Modifier.isStatic check in the GsonParser should be enough to solve this:

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions