当前位置: 首页>>代码示例>>Java>>正文


Java ObjectMapper.writeValueAsBytes方法代码示例

本文整理汇总了Java中com.fasterxml.jackson.databind.ObjectMapper.writeValueAsBytes方法的典型用法代码示例。如果您正苦于以下问题:Java ObjectMapper.writeValueAsBytes方法的具体用法?Java ObjectMapper.writeValueAsBytes怎么用?Java ObjectMapper.writeValueAsBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.fasterxml.jackson.databind.ObjectMapper的用法示例。


在下文中一共展示了ObjectMapper.writeValueAsBytes方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: convertObjectToJsonBytes

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
/**
 * Convert an object to JSON byte array.
 *
 * @param object
 *            the object to convert
 * @return the JSON byte array
 * @throws IOException
 */
public static byte[] convertObjectToJsonBytes(Object object)
        throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);

    JavaTimeModule module = new JavaTimeModule();
    module.addSerializer(OffsetDateTime.class, JSR310DateTimeSerializer.INSTANCE);
    module.addSerializer(ZonedDateTime.class, JSR310DateTimeSerializer.INSTANCE);
    module.addSerializer(LocalDateTime.class, JSR310DateTimeSerializer.INSTANCE);
    module.addSerializer(Instant.class, JSR310DateTimeSerializer.INSTANCE);
    module.addDeserializer(LocalDate.class, JSR310LocalDateDeserializer.INSTANCE);
    mapper.registerModule(module);

    return mapper.writeValueAsBytes(object);
}
 
开发者ID:GastonMauroDiaz,项目名称:buenojo,代码行数:24,代码来源:TestUtil.java

示例2: asEvent

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
public InputEvent asEvent() {
    ObjectMapper objectMapper = new ObjectMapper();
    byte[] body;
    try {
        body = objectMapper.writeValueAsBytes(req);
    } catch (JsonProcessingException e) {
        throw new RuntimeException(e);
    }

    System.err.println("Req:" + new String(body));

    return new InputEventBuilder()
       .withHeader(FLOW_ID_HEADER, flowId)
       .withHeader("Content-type", "application/json")
       .withBody(new ByteArrayInputStream(body))
       .build();
}
 
开发者ID:fnproject,项目名称:fdk-java,代码行数:18,代码来源:FlowsContinuationInvokerTest.java

示例3: convertObjectToJsonBytes

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
/**
 * Convert an object to JSON byte array.
 *
 * @param object
 *            the object to convert
 * @return the JSON byte array
 * @throws IOException
 */
public static byte[] convertObjectToJsonBytes(Object object)
        throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);

    JavaTimeModule module = new JavaTimeModule();
    mapper.registerModule(module);

    return mapper.writeValueAsBytes(object);
}
 
开发者ID:asanzdiego,项目名称:codemotion-2017-taller-de-jhipster,代码行数:19,代码来源:TestUtil.java

示例4: serializeNullValue

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
@Test
public void serializeNullValue() throws IOException {
	final TestEntityString entity = new TestEntityString();
	entity.setS(null);
	final ObjectMapper mapper = new VPackMapper();
	mapper.setSerializationInclusion(Include.ALWAYS);
	final VPackSlice vpack = new VPackSlice(mapper.writeValueAsBytes(entity));
	assertThat(vpack, is(notNullValue()));
	final VPackSlice s = vpack.get("s");
	assertThat(s.isNull(), is(true));
}
 
开发者ID:arangodb,项目名称:jackson-dataformat-velocypack,代码行数:12,代码来源:VPackSerializeDeserializeTest.java

示例5: convertObjectToJsonBytes

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
/**
 * Convert an object to JSON byte array.
 *
 * @param object the object to convert
 * @return the JSON byte array
 * @throws IOException
 */
public static byte[] convertObjectToJsonBytes(Object object)
    throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);

    JavaTimeModule module = new JavaTimeModule();
    mapper.registerModule(module);

    return mapper.writeValueAsBytes(object);
}
 
开发者ID:Cinderpup,项目名称:RoboInsta,代码行数:18,代码来源:TestUtil.java

示例6: main

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {

        AceApplicationConfig aceApplicationConfig=new AceApplicationConfig();

        ObjectMapper objectMapper=new ObjectMapper();
        byte[] bytes=objectMapper.writeValueAsBytes(aceApplicationConfig);
        //BeanSerializer jsonSerializer=new BeanSerializer();
        aceApplicationConfig= objectMapper.readValue(bytes,aceApplicationConfig.getClass());
        System.out.println(aceApplicationConfig.getPackages());
        Pattern p = Pattern.compile(".?.html|.jpg|.png|.css|.js");
        System.out.println(p.matcher("a.html").find());
        System.out.println(p.matcher("a.htm").find());
        System.out.println(p.matcher("a.css").find());
        System.out.println(p.matcher("a.js").find());
        System.out.println(TestChar.class.getClass());
        System.out.println(TestChar.class);



        LocalDateTime now=LocalDateTime.now();
        LocalDateTime dateTime= LocalDateTime.of(2017,4,19,6,6);

        System.out.println(now);
        System.out.println(dateTime);

        System.out.println(now.toLocalDate().equals(dateTime.toLocalDate()));


        char a=(char) 35;
        System.out.println(a);
        a=(char) 61;
        System.out.println(a);

    }
 
开发者ID:ChenXun1989,项目名称:ace,代码行数:35,代码来源:TestChar.java

示例7: initTypeInclusion

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
protected void initTypeInclusion(ObjectMapper mapObjectMapper) {
    TypeResolverBuilder<?> mapTyper = new DefaultTypeResolverBuilder(DefaultTyping.NON_FINAL) {
        public boolean useForType(JavaType t) {
            switch (_appliesFor) {
            case NON_CONCRETE_AND_ARRAYS:
                while (t.isArrayType()) {
                    t = t.getContentType();
                }
                // fall through
            case OBJECT_AND_NON_CONCRETE:
                return (t.getRawClass() == Object.class) || !t.isConcrete();
            case NON_FINAL:
                while (t.isArrayType()) {
                    t = t.getContentType();
                }
                // to fix problem with wrong long to int conversion
                if (t.getRawClass() == Long.class) {
                    return true;
                }
                if (t.getRawClass() == XMLGregorianCalendar.class) {
                    return false;
                }
                return !t.isFinal(); // includes Object.class
            default:
                // case JAVA_LANG_OBJECT:
                return (t.getRawClass() == Object.class);
            }
        }
    };
    mapTyper.init(JsonTypeInfo.Id.CLASS, null);
    mapTyper.inclusion(JsonTypeInfo.As.PROPERTY);
    mapObjectMapper.setDefaultTyping(mapTyper);
    
    // warm up codec
    try {
        byte[] s = mapObjectMapper.writeValueAsBytes(1);
        mapObjectMapper.readValue(s, Object.class);
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:42,代码来源:JsonJacksonCodec.java

示例8: convertObjectToJsonBytes

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
public static byte[] convertObjectToJsonBytes(Object object) throws IOException {
    ObjectMapper om = new ObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL);
    return om.writeValueAsBytes(object);
}
 
开发者ID:hmcts,项目名称:document-management-store-app,代码行数:5,代码来源:TestUtil.java

示例9: writeToGameEngineActivity

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
public boolean writeToGameEngineActivity(int attempt, String user, String pass, String code) {
    if (attempt > 5) {
        KRFAM.Toast("Failed to write to '" + codeName + "' A.D File.\nHave you allowed KRFAM to have root access?");
        return false;
    }
    if (installed == true) {

        SaveData value = new SaveData();
        value.m_UUID = user;
        value.m_AccessToken = pass;
        value.m_MyCode = code;
        value.m_ConfirmedVer = 0;

        String _iv = createPassword();
        byte[] iv = _iv.getBytes();

        KRFAM.log("iv " + _iv);
        try {


            MessagePack.PackerConfig config = new MessagePack.PackerConfig().withStr8FormatSupport(false);
            ObjectMapper objectMapper = new ObjectMapper(new MessagePackFactory(config));
            byte[] bytes = objectMapper.writeValueAsBytes(value);

            Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
            SecretKeySpec skeySpec = new SecretKeySpec(this.EncryptKey.getBytes(), "AES");
            cipher.init(Cipher.ENCRYPT_MODE, skeySpec, new IvParameterSpec(iv));
            byte[] encrypted = cipher.doFinal(bytes);

            OutputStream is = new FileOutputStream(SaveFile);
            LittleEndianDataOutputStream binaryWriter = new LittleEndianDataOutputStream(is);

            int num1 = new Random().nextInt();

            byte num2 = (byte) (num1 & 127);
            int num3 = (int) ((long) num1 & 4294902015L) | 65280 & 19 << 8; // 19 denotes 171101
            /* 16 - 20: _170404,  _170713,  _171101,  _latest, */

            binaryWriter.writeInt(num3);

            for (int index = 0; index < iv.length; ++index) iv[index] += (byte) (96 + (int) (byte) index);

            binaryWriter.writeByte((byte) ((int) iv.length + (int) num2));
            binaryWriter.write(iv);

            binaryWriter.writeInt(encrypted.length);
            binaryWriter.write(encrypted);

        }  catch (Exception ex) {
            KRFAM.log(ex);
            KRFAM.log(codeName + " > Failed to Write A.D File");
            KRFAM.forcePermission(adFile);
            KRFAM.forcePermission(adFile.getParentFile());
        }

        KRFAM.log("saved uu " + uuid);
        KRFAM.log("saved at " + accessToken);

        updateFromADFile();
        if (uuid.equals(user) && accessToken.equals(pass)) {
            return true;
        } else {
            KRFAM.forcePermission(adFile);
            KRFAM.forcePermission(adFile.getParentFile());
            return writeToGameEngineActivity(attempt + 1, user, pass, code);
        }
    } else {
        KRFAM.Toast(codeName + " not installed");
        return false;
    }
}
 
开发者ID:iebb,项目名称:Kasumi,代码行数:72,代码来源:Server.java

示例10: encode

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
/**
 * Encode.
 *
 * @param json the json
 * @return the byte[]
 * @throws IOException Signals that an I/O exception has occurred.
 */
public byte[] encode(JsonNode json) throws IOException{
	ObjectMapper mapper = new ObjectMapper();
	return mapper.writeValueAsBytes(json);
}
 
开发者ID:ac-silva,项目名称:desafio-pagarme,代码行数:12,代码来源:JsonNodeFormatter.java


注:本文中的com.fasterxml.jackson.databind.ObjectMapper.writeValueAsBytes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。