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

How can I define a GraphQL DTO attribute holding raw JSON? #498

Open
midmarch opened this issue Jun 3, 2024 · 0 comments
Open

How can I define a GraphQL DTO attribute holding raw JSON? #498

midmarch opened this issue Jun 3, 2024 · 0 comments

Comments

@midmarch
Copy link

midmarch commented Jun 3, 2024

Is it possible to define an attribute with raw JSON?

I have got the following DTO, with the property `geoShape is raw GeoJSON JSON.

import io.leangen.graphql.annotations.GraphQLInputField;
import io.leangen.graphql.annotations.GraphQLQuery;

public class GeoLocation {

  /**
     * Geo
     */
  @GraphQLQuery
  @GraphQLInputField
  private String geoShape;
}

Returning the following result querying for that attribute:

{
  "geoShape": "{ \"type\": \"Feature\", \"geometry\": { \"type\": \"Point\",  \"coordinates\": [125.6, 10.1]   }, \"properties\": {      \"name\": \"Dinagat Islands\"  }  }"
}  

What I like to havem is the following:

{
  "geoShape": {
    "type": "Feature",
     "geometry": {
      "type": "Point",
      "coordinates": [125.6, 10.1]
    },
    "properties": {
      "name": "Dinagat Islands"
    } 
  }
}  

I tried to add @JsonRawValue

import com.fasterxml.jackson.annotation.JsonRawValue;
import io.leangen.graphql.annotations.GraphQLInputField;
import io.leangen.graphql.annotations.GraphQLQuery;

public class GeoLocation {

 /**
    * Geo
    */
 @GraphQLQuery
 @GraphQLInputField
 @JsonRawValue
 private String geoShape;
}

But that made no difference. Also tried to use a Jackson JsonNode, instread of a String, which resulted in Runtime errors.

Do you have any advice?

@kaqqao kaqqao transferred this issue from leangen/graphql-spqr-samples Jun 3, 2024
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

1 participant