Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

uk.dioxic.mgenerate:mgenerate-parent

Package Overview
Maintainers
1
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

uk.dioxic.mgenerate:mgenerate-parent

Parent project for mgenerate4j

  • 0.0.5
  • Source
  • Maven

Version published
Maintainers
1
Source

travis maven

mgenerate4j is a tool for generating rich JSON documents from a template.

It can be used as a standalone application or as a library and is also extendable if you need to do something that isn't covered by the out-of-the-box functions.

The core syntax is largely the same as mgeneratejs by Thomas Rueckstiess.

To find out more, please check out the mgenerate4j wiki.

Example

Here we have a template that defines 3 fields; a random name, a random age and an array with 2 random email address.

Template
{ "name": "$name", "age": "$age", "emails": { "$array": { "of": "$email", "number": 2} } }
Output
{"name": "Jeffery Dooley", "age": 71, "emails": ["daisy.monahan@hotmail.com", "jacey.bauch@hotmail.com"]}
{"name": "Durward Morar", "age": 3, "emails": ["osborne.kassulke@hotmail.com", "amparo.stokes@gmail.com"]}
{"name": "Reyes Cartwright", "age": 42, "emails": ["candida.macejkovic@hotmail.com", "kasey.vandervort@yahoo.com"]}
{"name": "Naomi Nicolas", "age": 117, "emails": ["ottilie.murazik@gmail.com", "dillon.marvin@hotmail.com"]}
{"name": "Athena Buckridge", "age": 36, "emails": ["aryanna.tromp@gmail.com", "celestino.buckridge@gmail.com"]}

Quickstart

Assuming git and Maven installed:

$ git clone https://github.com/dioxic/mgenerate4j.git
$ mvn clean package
$ java -jar mgenerate-core/target/mgenerate.jar example-template.json

To import as a maven dependency:

<dependency>
    <groupId>uk.dioxic.mgenerate</groupId>
    <artifactId>mgenerate-core</artifactId>
    <version>0.0.5</version>
</dependency>

To import as a gradle dependency:

dependencies {
    compile 'uk.dioxic.mgenerate:mgenerate-core:0.0.5'
}

Note: precompiled executable jars are also available in releases.

Usage

Standalone

Usage: mgenerate [-h] [--debug] [-n=<number>] [-o=<output>] TEMPLATE
      TEMPLATE            template file path
      --debug             debug logging
  -h, --help              display a help message
  -n, --number=<number>   number of documents to generate (default: 10)
  -o, --out=<output>      output file path
$ java -jar mgenerate.jar template.json

Library

MongoClientSettings mcs = MongoClientSettings.builder()
        .codecRegistry(TemplateCodec.getCodecRegistry())
        .build();

Template template = Template.from("c:\\tmp\\mongo.json");
MongoCollection<Template> collection = MongoClients.create(mcs)
        .getDatabase("test")
        .getCollection("mgen", Template.class);

collection.insertOne(template);
collection.insertOne(template);
collection.insertOne(template);

This will result in 3 different documents being inserted since the template is hydrated during encoding.

License

Apache 2.0

FAQs

Package last updated on 04 Oct 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc