<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by David Král on Medium]]></title>
        <description><![CDATA[Stories by David Král on Medium]]></description>
        <link>https://medium.com/@kraldav?source=rss-a2ef011a2423------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*nHMmTRZHW7YvI527.jpg</url>
            <title>Stories by David Král on Medium</title>
            <link>https://medium.com/@kraldav?source=rss-a2ef011a2423------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 21:52:57 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kraldav/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Helidon JSON — Fast JSON Without Furious Runtime Code]]></title>
            <link>https://medium.com/helidon/helidon-json-fast-json-without-furious-runtime-code-f2fd936b2ba7?source=rss-a2ef011a2423------2</link>
            <guid isPermaLink="false">https://medium.com/p/f2fd936b2ba7</guid>
            <category><![CDATA[declarative]]></category>
            <category><![CDATA[json]]></category>
            <category><![CDATA[helidon]]></category>
            <dc:creator><![CDATA[David Král]]></dc:creator>
            <pubDate>Fri, 27 Mar 2026 12:44:42 GMT</pubDate>
            <atom:updated>2026-03-27T12:44:42.278Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6Z8MPd0J3XvMWZRkDiPyKA.png" /></figure><p>JSON is everywhere in modern Java services. Configuration, REST payloads, messaging — almost every application serializes and deserializes JSON in some way. Traditionally, JSON binding frameworks rely on runtime reflection or runtime-generated bytecode to keep things flexible.</p><p>Helidon takes a different approach.</p><p>With Helidon JSON, Helidon moves JSON metadata processing to build time and generates dedicated serializers and deserializers during the compilation process. The result is faster startup, predictable runtime behavior, and zero reflection while keeping a familiar, annotation-driven programming model.</p><h3>Why Helidon JSON?</h3><p>Most JSON frameworks discover structure at runtime:</p><ul><li>They scan annotations via reflection</li><li>They inspect fields and methods dynamically</li><li>They often generate bytecode during application startup</li></ul><p>This approach works well for flexibility, but it has real costs:</p><ul><li>Reflection and runtime generation consume CPU and memory</li><li>Startup time increases</li><li>Behavior can differ across JVMs and environments</li><li>Native image builds require additional configuration</li><li>Debugging becomes significantly harder</li></ul><p>Helidon’s JSON binding avoids these issues by generating JSON mapping code during compilation, not at runtime.</p><h3>Runtime Bytecode Generation and Debugging</h3><p>Some high-performance JSON libraries avoid reflection by generating bytecode at runtime. While this can improve throughput, it introduces a serious downside:</p><p>Runtime-generated bytecode is difficult, if not impossible, to debug effectively.</p><p>Common problems include:</p><ul><li>No readable source code</li><li>Stack traces pointing to synthetic or anonymous classes</li><li>Breakpoints cannot be set meaningfully</li><li>Debuggers cannot step through generated logic</li></ul><p>When something goes wrong in production, diagnosing issues inside runtime-generated serializers is often guesswork.</p><p>Helidon’s approach avoids runtime-generated bytecode entirely. All JSON mapping code is:</p><ul><li>Generated at build time</li><li>Compiled as normal Java classes</li><li>Available in build output</li></ul><p>This makes failures easier to understand and significantly improves maintainability.</p><h3>How It Works</h3><p>At a high level, the process looks like this:</p><ol><li>You annotate your Java classes with Helidon JSON annotations</li><li>Annotation processors run during compilation</li><li>Helidon generates serializers and deserializers as Java source code</li><li>The generated code is compiled and packaged with your application</li><li>At runtime, Helidon uses plain Java code — no reflection, no runtime bytecode or annotation processing</li></ol><p>Nothing special happens at runtime. All the work is already done.</p><h3>Starting with Helidon JSON</h3><p>Helidon JSON consists of two main parts:</p><h4>1. Add the JSON Runtime Dependency</h4><pre>&lt;dependency&gt;<br>    &lt;groupId&gt;io.helidon.json&lt;/groupId&gt;<br>    &lt;artifactId&gt;helidon-json-binding&lt;/artifactId&gt;<br>&lt;/dependency&gt;</pre><p>This dependency provides the runtime API used to serialize and deserialize JSON using generated mappers.</p><h4>2. Enable Annotation Processing</h4><p>If annotation processing is not enabled, no JSON code will be generated. That means you would need to create your own converters for the given type, otherwise Helidon JSON would not be able to process/create the object.<br>To enable it, the following plugin configuration need to be added:</p><pre>&lt;plugin&gt;<br>    &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;<br>    &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;<br>    &lt;configuration&gt;<br>        &lt;annotationProcessorPaths&gt;<br>            &lt;path&gt;<br>                &lt;groupId&gt;io.helidon.bundles&lt;/groupId&gt;<br>                &lt;artifactId&gt;helidon-bundles-apt&lt;/artifactId&gt;<br>                &lt;version&gt;4.4.0&lt;/version&gt; &lt;!-- or higher --&gt;<br>            &lt;/path&gt;<br>        &lt;/annotationProcessorPaths&gt;<br>    &lt;/configuration&gt;<br>&lt;/plugin&gt;</pre><p>Once this is configured, JSON mappers are generated automatically during compilation and automatically registered to the runtime binding object.</p><p>With the annotation processors and JSON dependency set, we can now define our POJO classes.</p><p>Helidon keeps all JSON related annotations as nested annotations on a single class: io.helidon.json.binding.Json. This means there is no need to remember every possible framework annotation. Everything related to JSON binding lives in one place.</p><p>The basic annotation, which is always needed on every type you desire to generate converter for, is Json.Entity. This annotation is used as a marker for the annotation processor to generate JSON converter.</p><pre>import io.helidon.json.binding.Json;<br><br>@Json.Entity<br>public record Person(String name, int age) {<br>}</pre><p>Alternatively, if needed, the converter can be implemented manually by implementing one of the following interfaces:</p><ul><li>io.helidon.json.binding.JsonConverter - contains methods applicable for both serialization and deserialization</li><li>io.helidon.json.binding.JsonSerializer - contains methods applicable only for serialization</li><li>io.helidon.json.binding.JsonDeserializer - contains methods applicable only for deserialization</li></ul><p>However, in this case, the converter is not automatically registered later.</p><p>Once the converter for a desired type is created, we need to create an instance of io.helidon.json.binding.JsonBinding which is used for handling the serialization and deserialization process. It offers a well-known methods called serialize/deserialize with a different supported sources, such as IOStream, String, byte[] or Writer/Reader.</p><pre>public static void main(String[] args) {<br>    JsonBinding binding = JsonBinding.create();<br>    Person person = new Person(&quot;John&quot;, 30);<br><br>    String json = binding.serialize(person);<br><br>    String toDeserialize = &quot;{\&quot;firstName\&quot;:\&quot;John\&quot;,\&quot;age\&quot;:30}&quot;;<br>    Person deserialized = binding.deserialize(toDeserialize, Person.class);<br>}</pre><p>If the annotation processor was used to created the converter, everything will work out of the box, but if de/serializer was created manually, it needs to be registered to the JsonBinding object. For that, we need to change how JsonBinding is created and use builder to register the de/serializer.</p><pre>JsonBinding.builder()<br>    .addConverter(MyCustomPersonConverter.class)<br>    .build();</pre><p>This way one can also overwrite some built in coverters and adjust the desired type conversion process.</p><h3>What This JSON Binding Is Not</h3><p>Helidon’s JSON binding is not an implementation of the Jakarta JSON-B API and it does not aim to replicate every feature found in reflection-based JSON frameworks.</p><p>Specifically:</p><ul><li>There is no runtime classpath scanning</li><li>There is no reflective fallback for unannotated types</li><li>Only explicitly annotated types are eligible for binding</li></ul><p>This is a deliberate trade-off. Helidon can generate predictable, optimized code and fail early when configuration is incomplete.</p><h3>Supported Java Structures And Types</h3><p>The binding supports the most common Java types and structures used in modern services, including:</p><ul><li>Java records</li><li>Mutable POJOs</li><li>Immutable objects with constructors or factories</li><li>Builder-based models</li><li>Nested types</li><li>Collections, arrays, and maps</li><li>Enums</li></ul><p>In addition to these structures, the binding also supports commonly used Java value types such as date and time classes, numeric types like BigDecimal and BigInteger, as well as primitive types and their boxed counterparts.</p><h3>Performance</h3><p>To better understand the performance characteristics of Helidon JSON, we ran a set of benchmarks against several widely used JSON frameworks.</p><h4>Benchmark Setup</h4><ul><li>Benchmark framework: JMH</li><li>Java: 25</li><li>Metric<strong>:</strong> Throughput (ops/ms)</li></ul><p>The goal of these benchmarks is not to declare a universal “winner”, but to compare different architectural approaches under identical conditions.</p><h4>Selected frameworks</h4><p>Reflection based</p><ul><li>Jackson</li><li>Gson</li><li>Yasson (JSON-B API implementation)</li></ul><p>Bytecode generating</p><ul><li>Jsoniter</li><li>Jackson + Blackbird</li></ul><p>Java source code generating</p><ul><li>DSL-JSON</li><li>Helidon JSON</li></ul><h4>The first benchmark</h4><p>The first benchmark measures deserialization of a simple JSON object into a POJO containing a mix of primitive fields, strings, nullable values, and a nested object.</p><p><strong>JSON Input</strong></p><pre>{<br>    &quot;fieldTwo&quot;:2147,<br>    &quot;fieldOne&quot;:&quot;Hello&quot;,<br>    &quot;fieldThree&quot;:&quot;World&quot;,<br>    &quot;fieldFour&quot;:null,<br>    &quot;fieldFive&quot;:&quot;1234&quot;,<br>    &quot;fieldSix&quot;:4567,<br>    &quot;otherBean&quot;:{<br>        &quot;otherString&quot;:&quot;Hello there!&quot;<br>    }<br>}</pre><p><strong>Java Model</strong></p><pre>public class MyJavaBean {<br>    private String fieldOne;<br>    private int fieldTwo;<br>    private String fieldThree;<br>    private String fieldFour;<br>    private String fieldFive;<br>    private long fieldSix;<br>    private OtherBean otherBean;<br> <br> //getters/setters<br><br>}<br><br>public class OtherBean {<br>    private String otherString;<br> <br> //getters/setters<br>}</pre><p><strong>Benchmark results</strong></p><pre>Benchmark                                             Mode  Cnt      Score     Error   Units<br>BasicBeanBenchmarkString.dslJson                     thrpt   20   9704.785 ± 221.191  ops/ms<br>BasicBeanBenchmarkString.gson                        thrpt   20   2323.612 ±  42.516  ops/ms<br>BasicBeanBenchmarkString.helidon                     thrpt   20  11884.703 ±  58.014  ops/ms<br>BasicBeanBenchmarkString.jackson                     thrpt   20   2308.585 ±  44.688  ops/ms<br>BasicBeanBenchmarkString.jacksonBlackbird            thrpt   20   2389.436 ±  59.357  ops/ms<br>BasicBeanBenchmarkString.jsoniter                    thrpt   20  10300.555 ±  48.851  ops/ms<br>BasicBeanBenchmarkString.micronaut                   thrpt   20   2996.117 ±  62.236  ops/ms<br>BasicBeanBenchmarkString.yasson                      thrpt   20   1827.419 ±  40.930  ops/ms</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DFKkOG_bw2-r-LspnY2l9Q.png" /></figure><p><strong>Notes</strong></p><ul><li>Source code generating frameworks (Helidon JSON, DSL-JSON) and Jsoniter clearly outperform reflection-based approaches.</li><li>Jackson with Blackbird improves slightly over plain Jackson, but remains in the same performance category.</li><li>Helidon JSON achieves the highest throughput in this benchmark, closely followed by Jsoniter.</li></ul><h4>The second benchmark</h4><p>The second benchmark focuses on deserializing JSON containing collections and a map, which introduces additional complexity in object creation and type handling.</p><p><strong>JSON Input</strong></p><pre>{<br>  &quot;ints&quot;:[123,321],<br>  &quot;names&quot;:[&quot;John&quot;,&quot;Fred&quot;,&quot;Jane&quot;],<br>  &quot;map&quot;:{<br>    &quot;Tom&quot;:123.456789,<br>    &quot;Martin&quot;:98765.4321<br>  }<br>}</pre><p><strong>Java Model</strong></p><pre>public class CollectionsAndMap {<br>    private List&lt;String&gt; names;<br>    private Set&lt;Integer&gt; ints;<br>    private Map&lt;String, Double&gt; map;<br> <br> //getters/setters<br>}</pre><p><strong>Benchmark results</strong></p><pre>Benchmark                                             Mode  Cnt      Score     Error   Units<br>BeanWithCollectionsAndMapBenchmark.dslJson           thrpt   20   6600.491 ±  43.374  ops/ms<br>BeanWithCollectionsAndMapBenchmark.gson              thrpt   20   2049.613 ±  32.189  ops/ms<br>BeanWithCollectionsAndMapBenchmark.helidon           thrpt   20   8076.963 ± 285.543  ops/ms<br>BeanWithCollectionsAndMapBenchmark.jackson           thrpt   20   2524.322 ±  39.648  ops/ms<br>BeanWithCollectionsAndMapBenchmark.jacksonBlackbird  thrpt   20   2505.417 ±  18.456  ops/ms<br>BeanWithCollectionsAndMapBenchmark.jsoniter          thrpt   20   4798.060 ±  57.020  ops/ms<br>BeanWithCollectionsAndMapBenchmark.micronaut         thrpt   20   2424.316 ±  25.386  ops/ms<br>BeanWithCollectionsAndMapBenchmark.yasson            thrpt   20   1434.857 ±  12.368  ops/ms</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lKLQNNvp8z1mkyxGywtY9w.png" /></figure><p><strong>Notes</strong></p><ul><li>Helidon JSON maintains the highest throughput in this scenario.</li><li>Jsoniter performs well but drops more noticeably compared to the basic benchmark.</li><li>Reflection-based frameworks remain significantly slower when dealing with collections and maps.</li></ul><h3>Conclusion</h3><p>Helidon JSON moves JSON processing from runtime into the build phase. By generating strongly typed converter code during the compile time, it eliminates runtime model discovery, reflection, and dynamic decision making.</p><p>The result is predictable behavior, faster startup, and lower overhead which is especially valuable for microservices and native-image deployments. What runs at runtime is plain, generated Java code that the JVM can fully optimize and developers can easily inspect.</p><p>This approach intentionally trades some runtime flexibility for clarity and performance. For applications with stable models, compile-time JSON binding offers a simpler runtime model and fewer surprises compared to traditional runtime frameworks.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f2fd936b2ba7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/helidon/helidon-json-fast-json-without-furious-runtime-code-f2fd936b2ba7">Helidon JSON — Fast JSON Without Furious Runtime Code</a> was originally published in <a href="https://medium.com/helidon">Helidon</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Helidon Inject]]></title>
            <link>https://medium.com/helidon/helidon-injection-4f3321ee7231?source=rss-a2ef011a2423------2</link>
            <guid isPermaLink="false">https://medium.com/p/4f3321ee7231</guid>
            <category><![CDATA[helidon]]></category>
            <category><![CDATA[injection]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[David Král]]></dc:creator>
            <pubDate>Fri, 14 Mar 2025 10:04:37 GMT</pubDate>
            <atom:updated>2025-03-15T14:23:35.106Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zZQiW6nQ0UlLSCXACivjHQ.jpeg" /></figure><p>Injection is one of the fundamental building blocks of modern applications and to support that fully, we introduced the Helidon Inject.</p><p>Helidon injection is compile/build time based. This provides a significant performance boost since it eliminates the need for reflection or dynamic proxying at runtime, resulting in faster startup. Additionally, it integrates well with GraalVM Native Image, making it an efficient choice for high-performance applications.</p><p>Let’s first define some basic terms used in Helidon Inject:</p><h4>Dependency Injection</h4><p>Injection is a way to automatically provide instances of dependencies without having to create them manually. Instead of a class creating an object itself, something else (like a Service registry) hands it over when needed. This makes code cleaner, easier to manage, and more flexible.</p><p>For example, if a Car needs an Engine, instead of the Car making an Engine itself, it just asks for one, and the system provides it. This is called Dependency Injection (DI).</p><h4>Service registry</h4><p>A service registry is a tool that enables declarative programming by supporting inversion of control (IoC). Continuing with the Car analogy from the DI explanation, the service registry acts as that mentioned system the Car is asking to provide an Engine.</p><p>It manages the lifecycle of services, handles dependency injection, and ensures that the correct instances are provided where needed and without requiring manual instantiation.</p><h4>Contract</h4><p>A contract is a type that defines what the service registry should provide. It represents an API that will be used.</p><p>For simplicity, a contract can be thought of as an interface, but it can also be an abstract class or even a concrete class.</p><pre>public interface Vehicle {<br>     void startTheEngine();<br>}</pre><h4>Service</h4><p>This can be either a concrete class, which implements the contract (or is contract itself if it was a concrete class), or it can be a factory/producer, which creates a new instances to be registered into the service registry.</p><pre>@Service.Singleton<br>public class Car implements Vehicle {<br><br>    @Override<br>    public void startTheEngine() {<br>        System.out.println(&quot;Engine has started&quot;);<br>    }<br><br>}</pre><h4>Injection points</h4><p>Injection point is a place in your service, where it is possible to inject desired contract instances.</p><p>In Helidon, dependency injection can be done into the injection point in the following ways:</p><ol><li>Through a constructor annotated with <a href="https://helidon.io/docs/v4/apidocs/io.helidon.service.registry/io/helidon/service/registry/Service.Inject.html">@Service.Inject</a> - each parameter is considered an injection point; this is the recommended way of injecting dependencies (as it can be unit tested easily, and fields can be declared private final)</li><li>Through field(s) annotated with <a href="https://helidon.io/docs/v4/apidocs/io.helidon.service.registry/io/helidon/service/registry/Service.Inject.html">@Service.Inject</a> - each field is considered an injection point; this is not recommended, as the fields must be accessible (at least package local), and can’t be declared as final</li></ol><p>Injection points are satisfied by services that match the required contract and qualifiers. If more than one service satisfies an injection point, the service with the highest weight is chosen (see <a href="https://helidon.io/docs/v4/apidocs/io.helidon.common/io/helidon/common/Weight.html">@Weight</a>, <a href="https://helidon.io/docs/v4/apidocs/io.helidon.common/io/helidon/common/Weighted.html">Weighted</a>).</p><p>It is also important to note, that only services can have injection points.</p><p>Now, let’s take a look at how to create our first service to get started with dependency injection (DI).</p><p>Services are defined as either:</p><ul><li>Java classes annotated with ęither <a href="https://helidon.io/docs/v4/apidocs/io.helidon.service.registry/io/helidon/service/registry/Service.Singleton.html">@Service.Singleton</a>, <a href="https://helidon.io/docs/v4/apidocs/io.helidon.service.registry/io/helidon/service/registry/Service.PerLookup.html">@Service.PerLookup</a> or <a href="https://helidon.io/docs/v4/apidocs/io.helidon.service.registry/io/helidon/service/registry/Service.PerRequest.html">@Service.PerRequest</a> annotations</li><li>Any class with <a href="https://helidon.io/docs/v4/apidocs/io.helidon.service.registry/io/helidon/service/registry/Service.Inject.html">@Service.Inject</a> annotation even when it doesn’t have a scope annotation. In such a case, the scope of the service will be set as <a href="https://helidon.io/docs/v4/apidocs/io.helidon.service.registry/io/helidon/service/registry/Service.PerLookup.html">@Service.PerLookup</a>.</li></ul><p>Keep in mind that if you create any service instance directly, it will not get its injection points resolved! This works only when using service registry.</p><p>With that knowledge in mind, we can easily construct the following service:</p><pre>@Service.Singleton<br>public class Engine {<br><br>    public void start() {<br>        System.out.println(&quot;Engine has started&quot;);<br>    }<br><br>}</pre><p>Since we have our service defined now, we should also define ąn injection point, where its instance should be injected. For that, we will use our previous Carservice.</p><pre>@Service.Singleton<br>public class Car implements Vehicle {<br><br>    private final Engine engine;<br><br>    @Service.Inject<br>    public Car(Engine engine) {<br>        this.engine = engine;<br>    }<br><br>    @Override<br>    public void startTheEngine() {<br>        engine.start();<br>    }<br><br>}</pre><p>Since Helidon Inject is compile/build time injection, we need to add annotation processors to generate ServiceDescriptor classes. These classes contain information about each service and how they are wired together, eliminating the need for reflection.</p><p>Add this to you Maven pom.xml file:</p><pre>&lt;build&gt;<br>    &lt;plugins&gt;<br>        &lt;plugin&gt;<br>            &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;<br>            &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;<br>            &lt;configuration&gt;<br>                &lt;annotationProcessorPaths&gt;<br>                    &lt;path&gt;<br>                        &lt;groupId&gt;io.helidon.codegen&lt;/groupId&gt;<br>                        &lt;artifactId&gt;helidon-codegen-apt&lt;/artifactId&gt;<br>                        &lt;version&gt;4.2.0&lt;/version&gt;<br>                    &lt;/path&gt;<br>                    &lt;path&gt;<br>                        &lt;groupId&gt;io.helidon.service&lt;/groupId&gt;<br>                        &lt;artifactId&gt;helidon-service-codegen&lt;/artifactId&gt;<br>                        &lt;version&gt;4.2.0&lt;/version&gt;<br>                    &lt;/path&gt;<br>                &lt;/annotationProcessorPaths&gt;<br>            &lt;/configuration&gt;<br>        &lt;/plugin&gt;<br>    &lt;/plugins&gt;<br>&lt;/build&gt;</pre><p>Now it just needs to be tested. The easiest way is to make a mainmethod. The following piece of code initializes Service registry, searchs for our Car and execute it to print out Engine has started.</p><pre>public static void main(String[] args) {<br>    var vehicle = Services.get(Vehicle.class);<br>    vehicle.startTheEngine();<br>}</pre><p>The approach above is easy to use and particularly useful for testing purposes. There is no need to start complex servers to verify that services work as expected.</p><p>However, it is even possible to avoid doing this runtime lookup/discovery at all and get even more performance from your application startup.</p><p>For this purpose, we introduced generated class called ApplicationBinding. This class is generated by our Maven plugin and contains all the needed service bindings. Because of that, no runtime discovery and lookup is needed since it has already been done at build time.</p><p>To use this approach, simply add the following plugin among your Maven plugin in your pom.xml:</p><pre>&lt;plugin&gt;<br>    &lt;!-- Maven plugin that generates the application binding --&gt;<br>    &lt;groupId&gt;io.helidon.service&lt;/groupId&gt;<br>    &lt;artifactId&gt;helidon-service-maven-plugin&lt;/artifactId&gt;<br>    &lt;version&gt;4.2.0&lt;/version&gt;<br>    &lt;executions&gt;<br>        &lt;execution&gt;<br>            &lt;id&gt;create-application&lt;/id&gt;<br>            &lt;goals&gt;<br>                &lt;goal&gt;create-application&lt;/goal&gt;<br>            &lt;/goals&gt;<br>        &lt;/execution&gt;<br>    &lt;/executions&gt;<br>&lt;/plugin&gt;</pre><p>Now, get back to the class, which contains your main method and add this annotation on the class:</p><pre>@Service.GenerateBinding<br>public class MyMainClass {...}</pre><p>This <a href="https://helidon.io/docs/v4/apidocs/io.helidon.service.registry/io/helidon/service/registry/Service.GenerateBinding.html">@Service.GenerateBinding</a> annotation adds the instruction for the Helidon code generator, that it should generate the application binding.</p><p>Build your application and newly created ApplicationBinding class will appear among the generated sources. Now we need to start our <a href="https://helidon.io/docs/v4/apidocs/io.helidon.service.registry/io/helidon/service/registry/ServiceRegistry.html">ServiceRegistry</a> with this generated binding to take effect. Let’s use the same main method we used before, but modify it a bit.</p><pre>public static void main(String[] args) {<br>    // start the service registry - uses generated application binding to avoid reflection and runtime lookup<br>    ServiceRegistryManager.start(ApplicationBinding.create());<br>    <br>    var vehicle = Services.get(Vehicle.class);<br>    vehicle.startTheEngine();<br>}</pre><h4>Qualifiers</h4><p>Helidon Inject offers variety of different options to help your application handle injection better. One of these tools are qualifiers. Qualifier is a way to tell the framework which dependency to use when there are multiple options available.</p><p>Helidon Inject let’s you make your own qualifiers by simply adding “meta-annotation” <a href="https://helidon.io/docs/v4/apidocs/io.helidon.service.registry/io/helidon/service/registry/Service.Qualifier.html">@Service.Qualifier</a>on the custom annotation.</p><pre>@Service.Qualifier<br>public @interface Diesel {<br>}<br><br>@Service.Qualifier<br>public @interface Petrol {<br>}</pre><p>The @Diesel and @Petrol annotations serve as custom qualifiers, allowing us to specify the desired service. In this example, we change theEngine class a bit and transform it into the contract interface, and implement it with two services. Each service is annotated with the qualifier that best identifies it.</p><pre>public interface Engine {<br>    void start();<br>}<br><br>@Diesel<br>@Service.Singleton<br>public class DieselEngine implements Engine {<br><br>    @Override<br>    public void start() {<br>        System.out.println(&quot;Diesel engine has started&quot;);<br>    }<br><br>}<br><br>@Petrol<br>@Service.Singleton<br>public class PetrolEngine implements Engine {<br><br>    @Override<br>    public void start() {<br>        System.out.println(&quot;Petrol engine has started&quot;);<br>    }<br><br>}</pre><p>Once the services are created and qualified, they can be injected like any other service. To ensure the correct instance is injected, we use the same qualifier annotation at the injection point.</p><pre>@Service.Singleton<br>record SportsCar(@Petrol Engine engine) {<br>}<br><br>@Service.Singleton<br>record Truck(@Diesel Engine engine) {<br>}</pre><h4>Factories</h4><p>Up until this point, instances of our services were always created directly via constructor, but this is something not always desirable. We might need to construct the instance in a different way, from some external sources etc.</p><p>This is solved by several factory types provided by the Helidon.</p><ul><li><a href="https://helidon.io/docs/v4/se/injection#_supplier">Supplier</a></li><li><a href="https://helidon.io/docs/v4/se/injection#_servicesfactory">ServicesFactory</a></li><li><a href="https://helidon.io/docs/v4/se/injection#_injectionpointfactory">InjectionPointFactory</a></li><li><a href="https://helidon.io/docs/v4/se/injection#_qualifiedfactory">QualifiedFactory</a></li></ul><p>In this article we focus only on the java.util.function.Supplier which perfectly illustrates what these factories are intended for in general. If you are interested in more information to each of the factories, there is a link to our documentation inluded for each of them.</p><p>Supplier factories are intended to provide just a single instance. However, if needed, it can return also Optional&lt;MyContract&gt; if it is possible to not create the instance at all.</p><pre>@Service.Singleton<br>public class MyServiceProvider implements Supplier&lt;MyContract&gt; {<br>    @Override<br>    public MyContract get() {<br>        return new MyService();<br>    }<br>}</pre><h4>Summary</h4><p>In this article, I have provided a brief introduction to Helidon Inject. This framework offers much more functionality and configuration options than what was/could be covered here. To learn more, please refer to the official <a href="https://helidon.io/docs/v4/se/injection">Helidon Inject documentation</a>.</p><p>Since Helidon Inject is a brand-new addition, we would love to hear your feedback in the comments section. If you encounter any issues or have ideas for improving the framework, feel free to reach out on our public <a href="https://join.slack.com/t/helidon/shared_invite/enQtNDM1NjU3MjkyNDg2LWNiNGIzOGFhZDdjNzAyM2Y2MzlmMDI4NWY4YjE1OWQ2OTdkYTZkN2FlNDcxNmUyZmZmMTZhZmZhNWI2ZTI1NGI">Slack</a> or via our GitHub <a href="https://github.com/helidon-io/helidon/issues">issue tracker</a>!</p><h4>Important links</h4><ul><li><a href="https://helidon.io/docs/v4/se/injection">Inject documentation</a></li><li><a href="https://github.com/helidon-io/helidon-examples/tree/helidon-4.x/examples/inject">Inject examples</a></li><li><a href="https://github.com/helidon-io/helidon-examples/tree/helidon-4.x/examples/quickstarts/helidon-quickstart-inject">Inject quickstart</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4f3321ee7231" width="1" height="1" alt=""><hr><p><a href="https://medium.com/helidon/helidon-injection-4f3321ee7231">Helidon Inject</a> was originally published in <a href="https://medium.com/helidon">Helidon</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Helidon Web Client]]></title>
            <link>https://medium.com/helidon/helidon-web-client-72e22f5d509a?source=rss-a2ef011a2423------2</link>
            <guid isPermaLink="false">https://medium.com/p/72e22f5d509a</guid>
            <category><![CDATA[restful]]></category>
            <category><![CDATA[reactive-programming]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[helidon]]></category>
            <dc:creator><![CDATA[David Král]]></dc:creator>
            <pubDate>Mon, 23 Mar 2020 15:12:46 GMT</pubDate>
            <atom:updated>2020-06-23T13:00:41.768Z</atom:updated>
            <content:encoded><![CDATA[<h3>Helidon WebClient</h3><p>The new Helidon WebClient for Helidon SE 2.0 allows you to perform any HTTP requests to the target endpoint (via GET, PUT, etc.), and handle the provided response in a reactive way. The WebClient’s reactive approach means that you are no longer blocked while waiting for the data.</p><p>The experimental version of the Helidon WebClient is included in the 2.0.0 release. You can download it from <a href="https://search.maven.org/artifact/io.helidon.webclient/helidon-webclient/2.0.0/jar">Maven Central Repository</a>, or by including the following dependency in your project’s pom.xml.</p><pre>&lt;dependency&gt;<br>    &lt;groupId&gt;io.helidon.webclient&lt;/groupId&gt;<br>    &lt;artifactId&gt;helidon-webclient&lt;/artifactId&gt;<br>    &lt;version&gt;2.0.0&lt;/version&gt;<br>&lt;/dependency&gt;</pre><blockquote><strong><em>Note:</em></strong><em> WebClient is still experimental and not intended for production use. APIs and features are not yet fully tested and are subject to change.</em></blockquote><h3><strong>Features Overview</strong></h3><p>The Helidon 2.0 WebClient includes the following features:</p><ul><li><strong>Reactive approach</strong><br>Every executed request and response is handled in a reactive way. You will no longer have to wait for the server response. When the response is received, the client requests only the amount of data it can handle at that time. Therefore, the memory is not overflowed.</li><li><strong>Simple, builder-like setup and execution</strong><br>Every client and request is created by a builder pattern, so it improves readability and code maintenance.</li><li><strong>Following redirects</strong><br>The WebClient is able to follow the redirect chain and perform requests on the correct endpoint for you. You no longer have to point your client to the correct/final endpoint.</li><li><strong>Tracing, metrics and security propagation<br></strong>When you configure the Helidon WebServer to use tracing, metrics and security, the settings are automatically propagated to the WebClient and used during request/response.</li></ul><p>The Helidon WebClient is designed with simplicity in mind. The example below demonstrates a simple GET request to ‘target’ endpoint:</p><pre>WebClient client = WebClient.builder()<br>        .baseUri(&quot;http://localhost&quot;)<br>        .build();<br><br>Single&lt;String&gt; response = webClient.get()<br>        .path(&quot;/endpoint&quot;)<br>        .request(String.class);</pre><p>In this next example you can see that JsonObject is now being used as the return type. Since JsonObject processing is not present in the WebClient by default, it needs to be registered to the client builder using the corresponding add method as shown below:</p><pre>WebClient client = WebClient.builder()<br>        .baseUri(&quot;<a href="http://localhost/">http://localhost</a>&quot;)<br>        //Register only JSON-P reader<br>        .addReader(JsonpSupport.reader())<br>        //Register only JSON-P writer<br>        .addWriter(JsonpSupport.writer())<br>        //Register both JSON-P reader and writer<br>        .addMediaSupport(JsonpSupport.create())<br>        .build();</pre><p>You can now make requests to the endpoint using various methods such as GET or PUT.</p><pre>JsonObject entity = //some JsonObject entity<br>WebClient client = WebClient.<em>builder</em>()<br>        .baseUri(&quot;http://localhost&quot;)<br>        .addMediaSupport(JsonpSupport.create())<br>        .build();<br><br>Single&lt;JsonObject&gt; responseGet = webClient.get()<br>        .path(&quot;/endpoint&quot;)<br>        .request(JsonObject.class);</pre><pre>Single&lt;WebClientResponse&gt; responsePut = webClient.put()<br>        .path(&quot;/endpoint&quot;)<br>        .submit(entity);</pre><p>The Helidon WebClient is also highly configurable. While the default configuration is suitable for most common use cases, you can also configure it to handle your specific requirements as shown in the examples below:</p><pre>Config config = Config.create();<br>WebClient client = WebClient.builder()<br>        .baseUri(&quot;http://localhost&quot;)<br>        .config(config.get(&quot;client&quot;))<br>        .build();</pre><p>Or, using Helidon configuration such as yaml file:</p><pre>client:<br>  connect-timeout-millis: 2000<br>  read-timeout-millis: 2000<br>  follow-redirects: true<br>  max-redirects: 5<br>  headers:<br>    - name: &quot;Accept&quot;<br>        value: [&quot;application/json&quot;,&quot;text/plain&quot;]<br>  services:<br>    exclude: [&quot;some.webclient.service.Provider&quot;]<br>    config:<br>      metrics:<br>        - methods: [&quot;PUT&quot;, &quot;POST&quot;, &quot;DELETE&quot;]<br>          type: COUNTER<br>          name-format: &quot;client.counter.%1$s.%2$s&quot;</pre><p>This is a simplified configuration for the example. You can find a full version of the config <a href="https://github.com/oracle/helidon/blob/master/examples/webclient/standalone/src/main/resources/full-webclient-config.yaml">here</a>.</p><h3><strong>Samples</strong></h3><p>A sample project that shows you how to use the WebClient can be found in the <a href="https://github.com/oracle/helidon/tree/master/examples/webclient/standalone">Helidon repository</a>. These samples will give you a better understanding of how to use WebClient.</p><h3>Summary</h3><p>Helidon WebClient is still an experimental feature. Before making it final we need your feedback. Please try it and let us know how we can improve it by leaving a comment to this article, as an <a href="https://github.com/oracle/helidon/issues">issue</a> in our issues tracker or in our official <a href="https://join.slack.com/t/helidon/shared_invite/enQtNDM1NjU3MjkyNDg2LWNiNGIzOGFhZDdjNzAyM2Y2MzlmMDI4NWY4YjE1OWQ2OTdkYTZkN2FlNDcxNmUyZmZmMTZhZmZhNWI2ZTI1NGI">Slack</a> channel.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=72e22f5d509a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/helidon/helidon-web-client-72e22f5d509a">Helidon Web Client</a> was originally published in <a href="https://medium.com/helidon">Helidon</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>