content: package com.alibaba.fastjson2.primitves;
  
  import com.alibaba.fastjson2.JSONPath;
  import com.alibaba.fastjson2.JSONReader;
  import com.alibaba.fastjson2.JSONWriter;
  import com.alibaba.fastjson2.TestUtils;
  import com.alibaba.fastjson2.reader.ObjectReaderCreator;
  import com.alibaba.fastjson2.reader.ObjectReaderProvider;
  import com.alibaba.fastjson2.writer.ObjectWriter;
  import com.alibaba.fastjson2.writer.ObjectWriterCreator;
  import com.alibaba.fastjson2_vo.IntField1;
  import org.junit.jupiter.api.Test;
  
  import static org.junit.jupiter.api.Assertions.assertEquals;
  
  public class IntValueFieldTest {
      @Test
      public void test_arrayMapping() {
          ObjectWriterCreator[] creators = TestUtils.writerCreators();
  
          for (ObjectWriterCreator creator : creators) {
              ObjectWriter<IntField1> objectWriter = creator.createObjectWriter(IntField1.class);
  
              {
                  IntField1 vo = new IntField1();
                  vo.v0000 = 1;
                  JSONWriter jsonWriter = JSONWriter.of();
                  objectWriter.write(jsonWriter, vo);
                  assertEquals("{\"v0000\":1}", jsonWriter.toString());
              }
              {
                  IntField1 vo = new IntField1();
                  vo.v0000 = 1;
                  JSONWriter jsonWriter = JSONWriter.of();
                  jsonWriter.config(JSONWriter.Feature.BeanToArray);
                  objectWriter.write(jsonWriter, vo);
                  assertEquals("[1]", jsonWriter.toString());
              }
              {
                  IntField1 vo = new IntField1();
                  vo.v0000 = 1;
                  JSONWriter jsonWriter = JSONWriter.ofUTF8();
                  objectWriter.write(jsonWriter, vo);
                  assertEquals("{\"v0000\":1}", jsonWriter.toString());
              }
              {
                  IntField1 vo = new IntField1();
                  vo.v0000 = 1;
                  JSONWriter jsonWriter = JSONWriter.ofUTF8();
                  jsonWriter.config(JSONWriter.Feature.BeanToArray);
                  objectWriter.write(jsonWriter, vo);
                  assertEquals("[1]", jsonWriter.toString());
              }
          }
      }
  
      @Test
      public void test_jsonpath() {
          ObjectReaderCreator[] creators = TestUtils.readerCreators();
  
          for (ObjectReaderCreator creator : creators) {
              IntField1 vo = new IntField1();
  
              JSONReader.Context readContext
                      = new JSONReader.Context(
                              new ObjectReaderProvider(creator));
              JSONPath jsonPath = JSONPath
                      .of("$.v0000")
                      .setReaderContext(readContext);
              jsonPath.set(vo, 101);
              assertEquals(101, vo.v0000);
              jsonPath.set(vo, 102L);
              assertEquals(102, vo.v0000);
              jsonPath.set(vo, null);
              assertEquals(0, vo.v0000);
              jsonPath.set(vo, "103");
              assertEquals(103, vo.v0000);
              assertEquals(103, jsonPath.eval(vo));
  
              jsonPath.setInt(vo, 101);
              assertEquals(101, vo.v0000);
              jsonPath.setLong(vo, 102L);
              assertEquals(102, vo.v0000);
          }
      }
  }
  