GithubHelp home page GithubHelp logo

marioariasc / lagomkotlin Goto Github PK

View Code? Open in Web Editor NEW
18.0 3.0 6.0 50 KB

An example of Lightbend's Lagom project with Kotlin

License: Apache License 2.0

Shell 0.46% Java 76.62% Kotlin 22.91%
kotlin lagom lagom-framework microservices microservice

lagomkotlin's Introduction

lagomkotlin

An example of Lightbend's Lagom project with Kotlin

This is the basic Lagom's Java Hello World example. I duplicated all Java classes to Kotlin with the prefix K, e.g,:

GreetingMessage.java

package org.cakesolutions.hello.api;

import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;

@Immutable
@JsonDeserialize
public final class GreetingMessage {

  public final String message;

  @JsonCreator
  public GreetingMessage(String message) {
    this.message = Preconditions.checkNotNull(message, "message");
  }

  @Override
  public boolean equals(@Nullable Object another) {
    if (this == another)
      return true;
    return another instanceof GreetingMessage && equalTo((GreetingMessage) another);
  }

  private boolean equalTo(GreetingMessage another) {
    return message.equals(another.message);
  }

  @Override
  public int hashCode() {
    int h = 31;
    h = h * 17 + message.hashCode();
    return h;
  }

  @Override
  public String toString() {
    return MoreObjects.toStringHelper("GreetingMessage").add("message", message).toString();
  }
}

KGreetingMessage.kt

package org.cakesolutions.hello.api

import com.fasterxml.jackson.annotation.JsonCreator
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
import javax.annotation.concurrent.Immutable

@Immutable
@JsonDeserialize
data class KGreetingMessage @JsonCreator constructor(val message: String)

As you can see, Kotlin code is a lot shorter and readable

Run

Just type

mvn lagom:runAll

And then go to http://localhost:9000/api/hello/Kotlin

lagomkotlin's People

Contributors

marioariasc avatar orangy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.