Jmockdata
The plugin to mock the java data by random.
Install / Use
/learn @jsonzou/JmockdataREADME
<img src="https://img.shields.io/github/stars/jsonzou/jmockdata.svg?style=flat-square&label=Stars&logo=github" alt="github star">
Jmockdata
Jmockdata是一款实现模拟JAVA类型或对象的实例化并随机初始化对象的数据的工具框架。

The plugin of Jmockdata what through random algorithm mock java data.
Jmockdata插件通过随机算法模拟Java数据.

Feature
- 支持丰富多样的数据类型模拟,包括:Java基本类型、字符串、枚举、日期、数组、多维数组、集合[List|Set|Map]、枚举、Java对象等
- 支持通过正则表达式反向模拟数据
- 支持泛型
- 支持继承
- 支持循环依赖、自依赖(手动开启enabledCircle)
- 支持忽略字段
- 支持改变mockConfig来自定义模拟数据策略
- 支持自定义Mocker类扩展数据模拟类型
- 支持添加BeanMocker拦截器类改变模拟行为
- 支持JDK1.8+
Download
Jmockdata-4.3.0
Jar
Maven
<dependency>
<groupId>com.github.jsonzou</groupId>
<artifactId>jmockdata</artifactId>
<version>4.3.0</version>
</dependency>
Gradle
compile group: 'com.github.jsonzou', name: 'jmockdata', version: '4.3.0'
更多已发布版本下载
History version
Usage
基础类型
支持以下基础类型直接模拟
| 描述 | 类型 |
| ------ | ---------------------------------------- |
| 基础类型 | byte boolean char short int long float double |
| 包装类型包装 | Byte Boolean Character Short Integer Long Float Double |
| 常用类型 | BigDecimal BigInteger Date LocalDateTime LocalDate LocalTime java.sql.Timestamp String Enum |
| 多维数组 | 以上所有类型的多维数组 如:int[] int[][] int[][][] .... etc. |
//基本类型模拟
int intNum = JMockData.mock(int.class);
int[] intArray = JMockData.mock(int[].class);
Integer integer = JMockData.mock(Integer.class);
Integer[] integerArray = JMockData.mock(Integer[].class);
//常用类型模拟
BigDecimal bigDecimal = JMockData.mock(BigDecimal.class);
BigInteger bigInteger = JMockData.mock(BigInteger.class);
Date date = JMockData.mock(Date.class);
String str = JMockData.mock(String.class);
JAVA对象
模拟bean,被模拟的数据最好是plain bean,通过反射给属性赋值。
支持模拟继承而来的属性。
//模拟Java对象
public class BasicBean {
//基本类型
private byte byteNum;
private boolean booleanNum;
private char charNum;
private short shortNum;
private int integerNum;
private long longNum;
private float floatNum;
private double doubleNum;
//基本包装类型
private Byte byteBoxing;
private Boolean booleanBoxing;
private Character charBoxing;
private Short shortBoxing;
private Integer integerBoxing;
private Long longBoxing;
private Float floatBoxing;
private Double doubleBoxing;
//基本类型数组
private byte[] byteNumArray;
private boolean[] booleanNumArray;
private char[] charNumArray;
private short[] shortNumArray;
private int[] integerNumArray;
private long[] longNumArray;
private float[] floatNumArray;
private double[] doubleNumArray;
//基本类型二维数组
private byte[][] byteNumDoubleArray;
private boolean[][] booleanNumDoubleArray;
private char[][] charNumDoubleArray;
private short[][] shortNumDoubleArray;
private int[][] integerNumDoubleArray;
private long[][] longNumDoubleArray;
private float[][] floatNumDoubleArray;
private double[][] doubleNumDoubleArray;
//基本包装类型数组
private Byte[] byteBoxingArray;
private Boolean[] booleanBoxingArray;
private Character[] charBoxingArray;
private Short[] shortBoxingArray;
private Integer[] integerBoxingArray;
private Long[] longBoxingArray;
private Float[] floatBoxingArray;
private Double[] doubleBoxingArray;
//基本包装类型二维数组
private Byte[][] byteBoxingDoubleArray;
private Boolean[][] booleanBoxingDoubleArray;
private Character[][] charBoxingDoubleArray;
private Short[][] shortBoxingDoubleArray;
private Integer[][] integerBoxingDoubleArray;
private Long[][] longBoxingDoubleArray;
private Float[][] floatBoxingDoubleArray;
private Double[][] doubleBoxingDoubleArray;
//其他常用类型
private BigDecimal bigDecimal;
private BigInteger bigInteger;
private Date date;
private String string;
//其他常用类型数组
private BigDecimal[] bigDecimalArray;
private BigInteger[] bigIntegerArray;
private Date[] dateArray;
private String[] stringArray;
//其他常用类型二维数组
private BigDecimal[][] bigDecimalDoubleArray;
private BigInteger[][] bigIntegerDoubleArray;
private Date[][] dateDoubleArray;
private String[][] stringDoubleArray;
//集合、MAP数组
private List<Integer>[] listArray;
private Set<Integer>[] setArray;
private Map<Integer, String>[] mapArray;
//集合、MAP二维数组
private List<Integer>[][] listDoubleArray;
private Set<Integer>[][] setDoubleArray;
private Map<Integer, String>[][] mapDoubleArray;
//集合、MAP二维数组(内部数组)
private List<Integer[]>[][] listInnerArrayDoubleArray;
private Set<Integer[]>[][] setInnerArrayDoubleArray;
private Map<Integer[], String[]>[][] mapInnerArrayDoubleArray;
//集合、MAP二维数组(内部二维数组)
private List<Integer[][]>[][] listInnerDoubleArrayDoubleArray;
private Set<Integer[][]>[][] setInnerDoubleArrayDoubleArray;
private Map<Integer[][], String[][]>[][] mapInnerDoubleArrayDoubleArray;
//LIST
private List<Byte> byteBoxingList;
private List<Boolean> booleanBoxingList;
private List<Character> charBoxingList;
private List<Short> shortBoxingList;
private List<Integer> integerBoxingList;
private List<Long> longBoxingList;
private List<Float> floatBoxingList;
private List<Double> doubleBoxingList;
private List<BigDecimal> bigDecimalList;
private List<BigInteger> bigIntegerList;
private List<Date> dateList;
private List<String> stringList;
private List<List<String>> stringListList;
private List<Set<String>> stringSetList;
private List<Map<Integer, String>> mapList;
//数组LIST
private List<Byte[]> byteBoxingArrayList;
private List<Boolean[]> booleanBoxingArrayList;
private List<Character[]> charBoxingArrayList;
private List<Short[]> shortBoxingArrayList;
private List<Integer[]> integerBoxingArrayList;
private List<Long[]> longBoxingArrayList;
private List<Float[]> floatBoxingArrayList;
private List<Double[]> doubleBoxingArrayList;
private List<BigDecimal[]> bigDecimalArrayList;
private List<BigInteger[]> bigIntegerArrayList;
private List<Date[]> dateArrayList;
private List<String[]> stringArrayList;
//二维数组LIST
private List<Byte[][]> byteBoxingDoubleArrayList;
private List<Boolean[][]> booleanBoxingDoubleArrayList;
private List<Character[][]> charBoxingDoubleArrayList;
private List<Short[][]> shortBoxingDoubleArrayList;
private List<Integer[][]> integerBoxingDoubleArrayList;
private List<Long[][]> longBoxingDoubleArrayList;
private List<Float[][]> floatBoxingDoubleArrayList;
private List<Double[][]> doubleBoxingDoubleArrayList;
private List<BigDecimal[][]> bigDecimalDoubleArrayList;
private List<BigInteger[][]> bigIntegerDoubleArrayList;
private List<Date[][]> dateDoubleArrayList;
private List<String[][]> stringDoubleArrayList;
//SET忽略同List
//MAP
private Map<String, Integer> basicMap;
private Map<String[], Integer> keyArrayMap;
private Map<String, Integer[]> valueArrayMap;
private Map<String[], Integer[]> keyValueArrayMap;
private Map<String[][], Integer[][]> keyValueDoubleArrayMap;
private Map<List<String>, Map<String, Integer>> keyListValueMapMap;
private Map<List<String>[], Map<String, Integer>[]> keyArrayListValueArrayMapMap;
//getter setter省略...
}
//调用模拟数据的方法模拟Java对象
BasicBean basicBean = JMockData.mock(BasicBean.class);
容器类型(LIST,SET,MAP)
@Test
//******注意TypeReference要加{}才能模拟******
public void testTypeRefrence() {
//模拟基础类型,不建议使用这种方式,参考基础类型章节直接模拟。
Integer integerNum = JMockData.mock(new TypeReference<Integer>(){});
Integer[] integerArray = JMockData.mock(
Related Skills
node-connect
343.3kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
92.1kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
343.3kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
343.3kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
