Skip to content

Nosto/beanie

Repository files navigation

Beanie

Beanie is a simple library to sanity-check your bean ser-deser. Beanie catches a whole slew of issues such as:'

  • inconsistent naming of properties e.g. mixing snake and camel cases
  • mutable beans with setters
  • missing constructor arguments
  • issues with polymorphic serde

Installation

Beanie artifacts are published to AWS CodeArtifact. Before building, fetch a temporary token and expose it to Gradle (tokens expire after 12 hours):

export CODEARTIFACT_AUTH_TOKEN=$(aws codeartifact get-authorization-token \
  --domain <your-domain> \
  --domain-owner <your-domain-owner-account-id> \
  --region us-east-1 \
  --query authorizationToken \
  --output text)

Then add the CodeArtifact repository to your repositories block:

repositories {
    maven {
        url = uri("https://nosto-673366506863.d.codeartifact.us-east-1.amazonaws.com/maven/java/")
        credentials {
            username = "aws"
            password = System.getenv("CODEARTIFACT_AUTH_TOKEN")
        }
    }
}

After the repository is configured, declare the Beanie modules you need in dependencies as usual.

Usage

Usage in JUnit 4 (Vintage)

In order to use Beanie if you're using JUnit 4, you'll need to use the junit-vintage artifact. In order to get the test to be picked up and run by your test engine, you will need to include a test stub such as the one below into your test suite.

package com.example;

import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import com.fasterxml.jackson.databind.json.JsonMapper;
import com.nosto.beanie.AbstractJacksonBeanTest;
import com.nosto.beanie.BeanieProvider;
import com.nosto.beanie.JacksonBean;

@SuppressWarnings("JUnitTestCaseWithNoTests")
@RunWith(Parameterized.class)
public class CheckMyBeansTest extends AbstractJacksonBeanTest<JacksonBean> {

    public CheckMyBeansTest(Class<? extends JacksonBean> deserClass, String testName) {
        super(deserClass, concreteClass);
    }

    @Override
    protected BeanieProvider getBeanieProvider() {
        return JsonMapper::new;
    }
}

Usage in JUnit 5 (Jupiter)

In order to use Beanie if you're using JUnit 5, you'll need to use the junit-jupiter artifact. In order to get the test to be picked up and run by your test engine, you will need to include a test stub such as the one below into your test suite.

package com.example;

import com.fasterxml.jackson.databind.json.JsonMapper;
import com.nosto.beanie.BeanieProvider;
import com.nosto.beanie.JacksonBean;

public class CheckMyBeansTest extends AbstractJacksonBeanTest<JacksonBean> {

    @Override
    public BeanieProvider getBeanieProvider() {
        return JsonMapper::new;
    }
}

Authors

License

MIT License

About

A simple library to sanity-check your bean ser-deser

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors 4

  •  
  •  
  •  
  •  

Languages