Skip to content

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

Open
@midmarch

Description

@midmarch

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions