/src/main/java/com/alibaba/fastjson/serializer/IntArraySerializer.java
Java | 44 lines | 19 code | 7 blank | 18 comment | 4 complexity | 2dfdb1ef58d93c552a17ede1abf59653 MD5 | raw file
1/*
2 * Copyright 1999-2101 Alibaba Group.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package com.alibaba.fastjson.serializer;
17
18import java.io.IOException;
19import java.lang.reflect.Type;
20
21/**
22 * @author wenshao<szujobs@hotmail.com>
23 */
24public class IntArraySerializer implements ObjectSerializer {
25
26 public static IntArraySerializer instance = new IntArraySerializer();
27
28 public final void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType) throws IOException {
29 SerializeWriter out = serializer.getWriter();
30
31 if (object == null) {
32 if (out.isEnabled(SerializerFeature.WriteNullListAsEmpty)) {
33 out.write("[]");
34 } else {
35 out.writeNull();
36 }
37 return;
38 }
39
40 int[] array = (int[]) object;
41
42 out.writeIntArray(array);
43 }
44}