Skip to content

it will conflict when custom model named the same as java.lang.* #229

@jxnu-liguobin

Description

@jxnu-liguobin

Issue Description

  1. I want to know how to use custom scalar parsing when parsing JSON without using spring IOC
  2. i use graphql interface hava failed:
Cannot construct instance of `io.github.dreamylost.model.Character` (no Creators, like default constructor, exist): abstract types either need to be mapped to concrete types, have custom deserializer, or contain additional type information
 at [Source: (PushbackInputStream); line: 1, column: 17] (through reference chain: io.github.dreamylost.model.HeroQueryResponse["data"]->java.util.LinkedHashMap["hero"])

i use java main method, instance of spring bean,so i create a RestTemplate with new to execute request
this is my client example:

    @Override
    public Character hero(Episode episode) throws Exception {
        HeroQueryRequest heroQueryRequest = new HeroQueryRequest();
        heroQueryRequest.setEpisode(episode);

        CharacterResponseProjection characterResponseProjection = new CharacterResponseProjection();
        characterResponseProjection.id().name().onDroid(new DroidResponseProjection().id().name());

        GraphQLRequest graphQLRequest = new GraphQLRequest(heroQueryRequest, characterResponseProjection);
       //will error, I'm not familiar with this, so i create a issue
        HeroQueryResponse result = Config.restTemplate.exchange(URI.create(Config.productUrl), HttpMethod.POST, Config.httpEntity(graphQLRequest), HeroQueryResponse.class).getBody();

        assert result != null;
        return result.hero();

    }

Steps to Reproduce

List in detail the exact steps to reproduce the unexpected behavior.

Expected Result

Explain in detail what behavior you expected to happen.

Actual Result

Explain in detail what behavior actually happened.

Your Environment and Setup

  • graphql-java-codegen: E.g.: 2.2.1
  • Build tool: E.g.: SBT
  • Java tool: E.g.: Java 8u241
  • Mapping Config: E.g.:
import java.util

name := "sbt-codegen-exmaple"

version := "1.0.0-SNAPSHOT"

organization := "io.github.dreamylost"


enablePlugins(GraphQLCodegenPlugin)

libraryDependencies ++= GraphQLCodegen ++ Seq(
  "org.springframework" % "spring-web" % "5.2.7.RELEASE"
) ++  Seq(
  "org.apache.logging.log4j" %% "log4j-api-scala" % "11.0",
  "org.apache.logging.log4j" % "log4j-api" % "2.8.2",
  "org.apache.logging.log4j" % "log4j-core" % "2.8.2",
  "org.apache.logging.log4j" % "log4j-slf4j-impl" % "2.8.2")


graphqlSchemaPaths := Array("src/main/resources/schema.graphqls")
modelPackageName := Some("io.github.dreamylost.model")
apiPackageName := Some("io.github.dreamylost.api")
generateClient := Some(true)
generateApis := Some(true)
customTypesMapping := {
  val mapping = new util.HashMap[String, String]
  mapping.put("Email", "io.github.dreamylost.scalar.EmailScalar")
  mapping
}

Additional context

this is draft impl and example for sbt : https://github.com/jxnu-liguobin/graphql-java-codegen/tree/master/plugins/sbt/graphql-java-codegen-sbt-plugin , but i don't know about GraphQLCodegenConfiguration and if i impl GraphQLCodegenConfiguration, can not use settingKey in override method in sbt, so i do not impl it.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions