public static ObjectNode convertFromGHResponse(GHResponse ghResponse, TranslationMap translationMap, Locale locale,
            DistanceConfig distanceConfig) {
        ObjectNode json = JsonNodeFactory.instance.objectNode();

        if (ghResponse.hasErrors())
            throw new IllegalStateException(
                    "If the response has errors, you should use the method NavigateResponseConverter#convertFromGHResponseError");

        PointList waypoints = ghResponse.getBest().getWaypoints();

        final ArrayNode routesJson = json.putArray("routes");

        List<ResponsePath> paths = ghResponse.getAll();

        for (int i = 0; i < paths.size(); i++) {
            ResponsePath path = paths.get(i);
            ObjectNode pathJson = routesJson.addObject();

            putRouteInformation(pathJson, path, i, translationMap, locale, distanceConfig);
        }

        final ArrayNode waypointsJson = json.putArray("waypoints");
        for (int i = 0; i < waypoints.size(); i++) {
            ObjectNode waypointJson = waypointsJson.addObject();
            // TODO get names
            waypointJson.put("name", "");
            putLocation(waypoints.getLat(i), waypoints.getLon(i), waypointJson);
        }

        json.put("code", "Ok");
        // TODO: Maybe we need a different format... uuid: "cji4ja4f8004o6xrsta8w4p4h"
        json.put("uuid", UUID.randomUUID().toString().replaceAll("-", ""));

        return json;
    }
@Test
    public void barrierTest() {
        // There is a barrier https://www.openstreetmap.org/node/2206610569 on the route
        GHResponse rsp = hopper.route(new GHRequest(42.601991, 1.687227, 42.601616, 1.687888).setProfile(profile)
                .setPathDetails(Collections.singletonList("intersection")));

        ObjectNode json = NavigateResponseConverter.convertFromGHResponse(rsp, trMap, Locale.ENGLISH, distanceConfig);

        JsonNode steps = json.get("routes").get(0).get("legs").get(0).get("steps");

        JsonNode step = steps.get(1);

        JsonNode intersection = step.get("intersections").get(1);

        // checking order of entries
        assertEquals(0, intersection.get("out").asInt());

        JsonNode location = intersection.get("location");
        // The location of the barrier
        assertEquals(location.get(0).asDouble(), 1.6878903, .000001);
        assertEquals(location.get(1).asDouble(), 42.601764, .000001);

        int inPosition = intersection.get("in").asInt();
        int outPosition = intersection.get("out").asInt();
        JsonNode entry = intersection.get("entry");
        assertEquals(false, entry.get(inPosition).asBoolean());
        assertEquals(true, entry.get(outPosition).asBoolean());

        JsonNode bearings = intersection.get("bearings");
        double inBearing = bearings.get(inPosition).asDouble();
        double outBearing = bearings.get(outPosition).asDouble();

        // and these should be the bearings
        assertEquals(353, inBearing);
        assertEquals(171, outBearing);

        // and no additional intersection
        assertEquals(step.get("intersections").size(), 2);
    }