Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

service/pom.xml : dependency removed



LINK TO THE PULL REQUESTS :

sunbird-utils : https://github.com/project-sunbird/sunbird-utils/pull/366

sunbird-lms-mw : https://github.com/project-sunbird/sunbird-lms-mw/pull/460

sumbird-lms-service : https://github.com/project-sunbird/sunbird-lms-service/pull/193

Code to support to remove Gson and Use Jackson :

...

Snippet 1:

Code Block
languagejava

public class GsonToJackson {

  public static void main(String[] args) {

    ObjectMapper mapper = new ObjectMapper();
    String response = "{\"request\": { \"firstName\": \"Sso mock user\",\"phone\": \"9663933554\","
        + "  \"phoneVerified\": true,\"channel\": \"INFRA\",       \"orgExternalId\": \"intra111\","
        + "\"externalIds\":" + " [{ \"id\": \"sso_mock_user\", \"provider\": \"INFRA\",\"idType\": \"INFRA\" }] }}";

    try {
      JsonNode res = mapper.readTree(response);
      JsonNode request = res.get("request");
      if (request != null) {
        JsonNode externalIds = request.get("externalIds");
        System.out.println("Using JackSon : value of externalIds " + mapper.writeValueAsString(externalIds));
        JsonNode externalId = externalIds.get(0);
        System.out.println("Using JackSon : value of externalId " + mapper.writeValueAsString(externalId));
        System.out.println("Using JackSon : value of provider in externalId " + externalId.get("provider").asText());
      }
    } catch (Exception e) {
      System.out.println("Exception caught");
    }

    JsonParser parser = new JsonParser();
    JsonObject json = (JsonObject) parser.parse(response);

    Object request = json.get("request");
    if (request != null) {
      JsonObject value = (JsonObject) parser.parse(request.toString());
      JsonArray externalIds = (JsonArray) value.get("externalIds");
      System.out.println("Using Gson    : value of externalIds " + externalIds.toString());
      JsonObject externalId = (JsonObject) externalIds.get(0);
      System.out.println("Using Gson    : value of externalId " + externalId.toString());
      System.out.println("Using Gson    : value of provider in externalId " + externalId.get("provider").getAsString());
    }
  }
}

...

Snippet 2 :


Code Block
languagejava

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.gson.JsonObject;

public class GsonToJackson_2 {

  public static void main(String[] args) throws JsonProcessingException {
    ObjectMapper mapper = new ObjectMapper();
  
    JsonObject gson = new JsonObject();
    gson.addProperty("revocation_reason", "REVOCATION_REASON");
    gson.addProperty("revocation", false);
    gson.addProperty("reason", "REASON");
    
    System.out.println("Using Gson : Object to Json String conversion :"+ gson.toString());

    JsonNode jackson = mapper.createObjectNode();
    ((ObjectNode) jackson).put("revocation_reason", "REVOCATION_REASON");
    ((ObjectNode) jackson).put("revocation", false);
    ((ObjectNode) jackson).put("reason", "REASON");

    String jjsonString = mapper.writeValueAsString(jackson);
    System.out.println("Using Jackson : Object to Json String conversion : "+ jjsonString);
  }

}


...