Skip to content

Generated Models for Java have Invalid code #253

@jrshaffe

Description

@jrshaffe

When I run the generation for java I am getting code that doesn't compile. The errors all say

Non-static method 'getGson()' cannot be referenced from a static context

It looks like the following methods are being added to my all my models and

 /**
  * Create an instance of V1MyObject given an JSON string
  *
  * @param jsonString JSON string
  * @return An instance of V1MyObject
  * @throws IOException if the JSON string is invalid with respect to V1MyObject
  */
  public static V1MyObject fromJson(String jsonString) throws IOException {
    return JSON.getGson().fromJson(jsonString, V1MyObject.class);
  }

 /**
  * Convert an instance of V1MyObject to an JSON string
  *
  * @return JSON string
  */
  public String toJson() {
    return JSON.getGson().toJson(this);
  }

JSON is referring toio.kubernetes.client.openapi.JSON

and that method is defined as follows:

  public JSON setGson(Gson gson) {
    this.gson = gson;
    return this;
  }

https://github.com/kubernetes-client/java/blob/master/kubernetes/src/main/java/io/kubernetes/client/openapi/JSON.java#L120-L122.

I noticed that the JSON.java file looks like it wasn't updated at the same time as the other files in there. All the other ones say there were Automated from openapi generation release 1.27. Not sure if that helps at all.

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    lifecycle/staleDenotes an issue or PR has remained open with no activity and has become stale.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions