Convert a json-encoded view.

@param mo the model to rely on
@param in the view to decode
@return the resulting view
@throws JSONConverterException if the conversion failed
519978
public ModelView fromJSON(Model mo, JSONObject in) throws JSONConverterException {
        checkKeys(in, ModelViewConverter.IDENTIFIER);
        Object id = in.get(ModelViewConverter.IDENTIFIER);
        ModelViewConverter<? extends ModelView> c = json2java.get(id.toString());
        if (c == null) {
            throw new JSONConverterException("No converter available for a view having id '" + id + "'");
        }
        return c.fromJSON(mo, in);
    }
519334
public static String json(Object obj, boolean writeClass,
                              Converter<Object, Map<String, Object>> mc) throws IOException {
        if (obj == null)
            return NULL;
        StringWriter sw = new StringWriter();
        try {
            json(obj, sw, writeClass, mc);
            return sw.getBuffer().toString();
        } finally {
            sw.close();
        }
    }
1026757
static DataModelDto toDataModelDto(final String json) {
        try { return mapper.readValue(json, DataModelDto.class); }
        catch (IOException e) { throw new CalculationEngineException(e); }
    }
1336134
public static function moSms($json)
    {
        $fields = Deserialize::_fromJson($json);
        return Deserialize::_moSmsFromFields($json, $fields);
    }
186360
@POST
    @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
    @Path("{key}/{op}")
    public Response invokeMbeanOperation(
            MultivaluedMap<String, String> formParams,
            @PathParam("key") String key, @QueryParam("jsonp") String jsonp,
            @PathParam("op") String name) throws Exception {

        LOG.info("invoke " + key + " op=" + name);
        MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
        Map<String, String> params = new TreeMap<String, String>();
        for (Entry<String, List<String>> entry : formParams.entrySet()) {
            if (entry.getKey().equals("op"))
                continue;
            if (entry.getValue().size() > 0)
                params.put(entry.getKey(), entry.getValue().get(0));
            else
                params.put(entry.getKey(), "");
        }

        ObjectName objName = new ObjectName(key);
        MBeanInfo info = mBeanServer.getMBeanInfo(objName);
        for (MBeanOperationInfo op : info.getOperations()) {
            if (op.getName().equals(name)) {
                List<String> signature = new ArrayList<String>();
                for (MBeanParameterInfo s : op.getSignature()) {
                    signature.add(s.getType());
                }
                Object result = mBeanServer.invoke(objName, name, params
                        .values().toArray(new String[params.size()]), signature
                        .toArray(new String[signature.size()]));
                JSONObject json = new JSONObject();
                json.put("key", key);
                json.put("operation", name);
                if (result != null) {
                    json.put("response", result.toString());
                }
                json.put("type", op.getReturnType());

                StringWriter out = new StringWriter();
                if (jsonp.isEmpty()) {
                    json.write(out);
                } else {
                    out.append(jsonp).append("(");
                    json.write(out);
                    out.append(");");
                }
                return Response.ok(out.toString())
                        .type(MediaType.APPLICATION_JSON).build();
            }
        }

        return Response.serverError().build();
    }
37408
static DataSetDto toDataSetDto(final String json) {
        try { return mapper.readValue(json, DataSetDto.class); }
        catch (IOException e) { throw new CalculationEngineException(e); }
    }
235188
@Override
    public @Nonnull JsonMediaTypeCodec resolveJsonViewCodec(@Nonnull Class<?> viewClass) {
        ArgumentUtils.requireNonNull("viewClass", viewClass);
        JsonMediaTypeCodec codec = jsonViewCodecs.get(viewClass);
        if (codec == null) {

            ObjectMapper viewMapper = objectMapper.copy();
            viewMapper.setConfig(viewMapper.getSerializationConfig().withView(viewClass));
            codec = new JsonMediaTypeCodec(viewMapper, applicationConfiguration, codecConfiguration);
            jsonViewCodecs.put(viewClass, codec);
        }
        return codec;
    }
424435
private static <T> T jsonDecode(String responseContent, TypeReference<T> valueTypeRef) throws IOException {

      ObjectMapper mapper = new ObjectMapper();
      
      try {
         return mapper.<T>readValue(responseContent, valueTypeRef);
      } catch (JsonGenerationException e) {
         logger.severe("unable decode");
         throw new IOException(e);
      } catch (JsonMappingException e) {
         logger.severe("unable decode");
         throw new IOException(e.getMessage());
      }
   }
571063
private <T> T convertObject(byte[] json, Class<T> claz) throws IOException {
        TypeReference<RestSuccessResult<Map<?, ?>>> typeReference = new TypeReference<RestSuccessResult<Map<?, ?>>>() {
        };
        RestSuccessResult<T> successResponse = MAPPER.readValue(json, typeReference);
        Map<?, ?> data = (Map<?, ?>) successResponse.getData();
        return MAPPER.convertValue(data, claz);
    }
134876
@Bean
	@ConditionalOnMissingBean(name = "busJsonConverter")
	@StreamMessageConverter
	public AbstractMessageConverter busJsonConverter(
			@Autowired(required = false) ObjectMapper objectMapper) {
		return new BusJacksonMessageConverter(objectMapper);
	}
581298
public <T> T parse(String in, JsonReaderI<T> mapper) throws ParseException {
		return getPString().parse(in, mapper);
	}
468148
public static Workflow fromJson(String json) throws IOException {
        ObjectMapper mapper = new ObjectMapper();
        return mapper.readValue(json, Workflow.class);
    }
1010558
public static <T> T convertObject(String json, Class<T> clazz) throws IOException {
        try {
            if (clazz.isAnnotationPresent(Model.class)) {
                return MODEL_MAPPER.readValue(json, clazz);
            }
            return MAPPER.readValue(json, clazz);
        } catch (IOException e) {
            String error = String.format("Unable to parse given json '%s' into class '%s'.", json, clazz.getName());
            LOGGER.error(error, e);
            throw new IOException(error, e);
        }
    }
649370
public <T> T parse(byte[] in, JsonReaderI<T> mapper) throws ParseException {
		return getPBytes().parse(in, mapper);
	}
79237
public void finishJson(final JsonConvert convert, final org.redkale.service.RetResult ret) {
        this.contentType = this.jsonContentType;
        if (this.recycleListener != null) this.output = ret;
        if (ret != null && !ret.isSuccess()) {
            this.header.addValue("retcode", String.valueOf(ret.getRetcode()));
            this.header.addValue("retinfo", ret.getRetinfo());
        }
        finish(convert.convertTo(getBodyBufferSupplier(), ret));
    }
362982
public JSONArray toJSON(Collection<SatConstraint> e) throws JSONConverterException {
        JSONArray arr = new JSONArray();
        for (SatConstraint cstr : e) {
            arr.add(toJSON(cstr));
        }
        return arr;
    }
721217
public static RESTHandlerJsonException createRESTHandlerJsonException(Throwable e, JSONConverter converter, int status) {
        try {
            //See if we need to fetch a converter
            if (converter == null) {
                converter = JSONConverter.getConverter();
            }
            //Create a new OutputStream to avoid any corrupted data
            ByteArrayOutputStream os = new ByteArrayOutputStream();

            //Write the exception inside the output stream
            converter.writeThrowable(os, e);

            //Get the message from the output stream
            String exceptionMessage = os.toString("UTF-8");

            //return a Web exception with the new response
            return new RESTHandlerJsonException(exceptionMessage, status, true);

        } catch (IOException innerException) {
            //Since we got an exception while converting the error just write the actual exception text with an internal error code. This should never
            //happen because our JSONErrorOutputStream shouldn't ever throw an IOException
            return new RESTHandlerJsonException(e.getMessage(), status, true);

        } finally {
            JSONConverter.returnConverter(converter);
        }
    }