it will conflict when custom model named the same as java.lang.*
See original GitHub issueIssue Description
- I want to know how to use custom scalar parsing when parsing JSON without using spring IOC
- 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:
- Created 3 years ago
- Comments:23 (11 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Oh, you are right! So there are two issues:
typename()
is added only to unions as of now. It should be possible to specify it for interfaces too.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!
but i can not find typename() in CharacterResponseProjection, need some setting?