Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Abuse the JSON scalar #207

Closed
razilevin opened this issue Dec 16, 2023 · 4 comments
Closed

Abuse the JSON scalar #207

razilevin opened this issue Dec 16, 2023 · 4 comments

Comments

@razilevin
Copy link

razilevin commented Dec 16, 2023

In regards to

#93

seems like many projects abuse the JSON scalar so that their services can return a graph of any shape. Calling GQL services applying the same approach I get an exception thrown in class AbstractCustomJacksonDeserializer.

switch (p.currentToken()) {
			case VALUE_FALSE:
			case VALUE_TRUE:
				value = new BooleanValue(p.getBooleanValue());
				break;
			case VALUE_NUMBER_FLOAT:
				value = new FloatValue(p.getDecimalValue());
				break;
			case VALUE_NUMBER_INT:
				value = new IntValue(p.getBigIntegerValue());
				break;
			case VALUE_STRING:
				value = new StringValue(p.getText());
				break;
			case VALUE_NULL:
				value = null;
				break;
			default:
				throw new JsonParseException(p, "Non managed JSON token: " + p.currentToken()); //$NON-NLS-1$
			}

the token in question is '{'. I am having a hard time trying to work around this issue. Say I wanted it to work I would apply the following to your code base

  1. Extend AbstractCustomJacksonDeserializer
  2. Override your deserialize function
  3. Generate a new template based on your client_jackson_deserializers.vm.java and replace your base class with mine
  4. I get stuck in the implementation of the deserialize function.

I don't mind using a JsonNode as the return type. Any suggestions?

@etienne-sf
Copy link
Collaborator

Hello, it's the same issue as #205.

I'm working on it. But the issue is not in the plugin's code. It's in the graphql-java core tool.

I'll create a demo project, before filing an issue to the graphql-java team.

Etienne

@razilevin
Copy link
Author

Given this hack on the generated CustomJacksonDeserializers for just that mapping of JSON scalar using the following implementation everything works as expected.

@Override public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
			return p.readValueAsTree();
}

Can you explain to me why you think it is not in your implementation of the AbstractCustomJacksonDeserializer deserialize function?

@etienne-sf
Copy link
Collaborator

Hello,

Thank you for your comment.
I came to the same conclusion (that the issue is in the plugin).

This custom serialization / deserialization has become too complex. But I need to keep it for backward compatibility.
The main issue is to make it work for all possible cases.

Étienne

@etienne-sf
Copy link
Collaborator

Hello,

The 2.4 version has been released. It handles the JSON and Object custom scalars.

Etienne

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants