question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:23 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
kobylynskyicommented, Jul 17, 2020

Oh, you are right! So there are two issues:

  1. typename() is added only to unions as of now. It should be possible to specify it for interfaces too.
  2. Another issue is that customAnnotationsMapping is only supported for field-level and not class-level.

I will implement both of these issues on Friday/Saturday and you should get the build over the weekend. Plus I will document the approach of writing the serializer.

Thanks again for finding this!

1reaction
jxnu-liguobincommented, Jul 17, 2020

but i can not find typename() in CharacterResponseProjection, need some setting?

Read more comments on GitHub >

github_iconTop Results From Across the Web

JAVA: Conflicts with Same Package and class names present ...
1. From java's point of view: same package-name + same class-name = same class. · Try using static imports, access the variable directly...
Read more >
How to Fix java.lang.NoSuchMethodError in Java - Rollbar
NoSuchMethodError is a runtime error which occurs when a method is called ... This can lead to a version conflict, resulting in a...
Read more >
3 ways to solve java.lang.NoClassDefFoundError in Java J2EE
1. A simple example of NoClassDefFoundError is class belongs to a missing JAR file or JAR was not added into classpath or sometimes...
Read more >
Customizing JAXB Bindings
Specify that a model group should be bound to a class rather than a list. Specify that a fixed attribute can be bound...
Read more >
Language Guide | Protocol Buffers - Google Developers
You should consider writing application-specific custom validation ... latter name is converted to lower-case so that it does not conflict with the former)....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found