Package org.jtester.json.encoder.array

Source Code of org.jtester.json.encoder.array.ObjectArrayEncoder

package org.jtester.json.encoder.array;

import java.util.HashMap;

import org.jtester.json.encoder.JSONEncoder;
import org.jtester.json.encoder.object.PoJoEncoder;

@SuppressWarnings({ "rawtypes" })
public class ObjectArrayEncoder<T> extends ArraysEncoder<T[]> {

  public ObjectArrayEncoder(Class clazz) {
    super(clazz);
    if (this.clazz == Object.class) {
      this.clazz = HashMap.class;
    }
  }

  @Override
  protected int getArraySize(T[] target) {
    return target.length;
  }

  @Override
  protected JSONEncoder getEncoderByItem(Object item) {
    if (item == null) {
      return new PoJoEncoder(Object.class);
    }
    Class type = item.getClass();
    return JSONEncoder.get(type);
  }

  @Override
  protected Object getItemByIndex(T[] target, int index) {
    return target[index];
  }
}
TOP

Related Classes of org.jtester.json.encoder.array.ObjectArrayEncoder

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.