Skip to content
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
bd03700
Draft
patcher454 Jun 23, 2025
b34715e
Fix Prevent blocking and handle Notifications correctly
patcher454 Jun 27, 2025
e2433cb
Fix errors
patcher454 Jun 28, 2025
01e1997
Fix correctly parse object parameters in JsonRpcRequest
patcher454 Jun 30, 2025
f6e0ea5
Fix Rename to SimpleJsonRpcResponse
patcher454 Jul 1, 2025
25ad292
Add jsonRpcResponse of parameter type checking
patcher454 Jul 1, 2025
7a69c1f
Fix jsonRpcServie notification error
patcher454 Jul 3, 2025
2f65ec1
Test jsonRpcRequest
patcher454 Jul 3, 2025
f1842b0
Test jsonRpcResponse
patcher454 Jul 3, 2025
529171e
Test jsonRpcService
patcher454 Jul 3, 2025
9087bfb
Fix jsonRpcRequest params allow a null element
patcher454 Jul 3, 2025
25b89d0
Add requireNonNull
patcher454 Jul 3, 2025
04622c7
Fix incorrect variable name
patcher454 Jul 6, 2025
6475fdf
Fix jsonproperty name
patcher454 Jul 7, 2025
544921a
Fix Javadoc
patcher454 Jul 7, 2025
cb7d97b
Fix remove nullable
patcher454 Jul 7, 2025
3b41429
Fix requireNonNull
patcher454 Jul 8, 2025
047a343
Fix Error Message
patcher454 Jul 10, 2025
eea7afa
Fix Javadoc
patcher454 Jul 10, 2025
5a4cb2b
Fix Property final
patcher454 Jul 17, 2025
35186e1
Fix Shorten the code
patcher454 Jul 17, 2025
57aff5b
Fix test case
patcher454 Jul 17, 2025
ef47d49
fix
patcher454 Oct 23, 2025
dd3f83f
Merge branch 'json-rpc' into json_rpc
jrhee17 Oct 24, 2025
7317cad
fix
patcher454 Oct 24, 2025
2b558b3
Merge branch 'json_rpc' of https://github.com/patcher454/armeria into…
patcher454 Oct 24, 2025
4b2a6dc
fix
patcher454 Oct 24, 2025
cd1d60a
fix: Restore indentation
patcher454 Oct 24, 2025
1cb9eaf
fix: missing
patcher454 Oct 24, 2025
1443994
Merge branch 'json_rpc' of https://github.com/patcher454/armeria into…
patcher454 Oct 24, 2025
56aaee4
fix: DefaultJsonRpcResponse hashcode
patcher454 Oct 24, 2025
6606d68
fix: make parameters immutable and non-null
patcher454 Oct 25, 2025
a0b743b
fix: remove json rpc flag
patcher454 Oct 30, 2025
52344f3
fix
patcher454 Oct 30, 2025
176a7ea
fix: remove remain flag
patcher454 Oct 30, 2025
e4c355b
fix: add javadoc
patcher454 Oct 31, 2025
185079c
Merge branch 'json-rpc' into json_rpc
jrhee17 Nov 4, 2025
94560fe
lint
minwoox Nov 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright 2025 LY Corporation
*
* LY Corporation licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package com.linecorp.armeria.common.jsonrpc;

import static java.util.Objects.requireNonNull;

import com.fasterxml.jackson.annotation.JsonProperty;

import com.linecorp.armeria.common.annotation.Nullable;
import com.linecorp.armeria.common.annotation.UnstableApi;

/**
* The base for JsonRpcResponse.
*/
@UnstableApi
public abstract class AbstractJsonRpcResponse implements JsonRpcResponse {
@Nullable
private final Object result;

@Nullable
private final JsonRpcError error;

/**
* Creates a new instance with result.
*/
protected AbstractJsonRpcResponse(Object result) {
this.result = requireNonNull(result, "result");
this.error = null;
}

/**
* Creates a new instance with error.
*/
protected AbstractJsonRpcResponse(JsonRpcError error) {
this.result = null;
this.error = requireNonNull(error, "error");
}

@Override
@JsonProperty
public final @Nullable Object result() {
return result;
}

@Override
@JsonProperty
public final @Nullable JsonRpcError error() {
return error;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
/*
* Copyright 2025 LY Corporation
*
* LY Corporation licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package com.linecorp.armeria.common.jsonrpc;

import static com.google.common.base.Preconditions.checkArgument;
import static java.util.Objects.requireNonNull;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableList;

import com.linecorp.armeria.common.annotation.Nullable;
import com.linecorp.armeria.internal.common.JacksonUtil;

/**
* Default {@link JsonRpcRequest} implementation.
*/
final class DefaultJsonRpcRequest implements JsonRpcRequest {
static final ObjectMapper objectMapper = JacksonUtil.newDefaultObjectMapper();

@Nullable
private final Object id;
private final String method;
private final JsonRpcParameter params;
private final JsonRpcVersion version;

DefaultJsonRpcRequest(@Nullable Object id, String method, Iterable<?> params) {
this(id, method, copyParams(params), JsonRpcVersion.JSON_RPC_2_0.getVersion());
}

DefaultJsonRpcRequest(@Nullable Object id, String method, Object... params) {
this(id, method, copyParams(params), JsonRpcVersion.JSON_RPC_2_0.getVersion());
}

DefaultJsonRpcRequest(@Nullable Object id, String method, Map<String, Object> params) {
this(id, method, copyParams(params), JsonRpcVersion.JSON_RPC_2_0.getVersion());
}

private DefaultJsonRpcRequest(
@Nullable Object id,
String method,
Object params,
String version) {
checkArgument(JsonRpcVersion.JSON_RPC_2_0.getVersion().equals(version),
"jsonrpc: %s (expected: 2.0)", version);
checkArgument(id == null || id instanceof Number || id instanceof String,
"id type: %s (expected: Null or Number or String)",
id != null ? id.getClass().getName() : "null");
checkArgument(params instanceof List || params instanceof Map,
"params type: %s (expected: List or Map)",
params != null ? params.getClass().getName() : "null");

@SuppressWarnings("unchecked")
final JsonRpcParameter rpcParams =
params instanceof List ? JsonRpcParameter.of((List<Object>) params)
: JsonRpcParameter.of((Map<String, Object>) params);

this.id = id;
this.method = requireNonNull(method, "method");
this.params = rpcParams;
this.version = JsonRpcVersion.JSON_RPC_2_0;
}

@JsonCreator
private static DefaultJsonRpcRequest fromJson(
@JsonProperty("id") @Nullable Object id,
@JsonProperty("method") String method,
@JsonProperty("params") @Nullable Object params,
@JsonProperty("jsonrpc") String version) {

if (params == null) {
return new DefaultJsonRpcRequest(id, method, ImmutableList.of());
}

if (params instanceof Iterable) {
return new DefaultJsonRpcRequest(id, method, (Iterable<?>) params);
}

return new DefaultJsonRpcRequest(id, method, params, version);
}

private static List<Object> copyParams(Iterable<?> params) {
requireNonNull(params, "params");
if (params instanceof ImmutableList) {
//noinspection unchecked
return (List<Object>) params;
}

// Note we do not use ImmutableList.copyOf() here,
// because it does not allow a null element and we should allow a null argument.
final List<Object> copy;
if (params instanceof Collection) {
copy = new ArrayList<>(((Collection<?>) params).size());
} else {
copy = new ArrayList<>(8);
}

for (Object p : params) {
copy.add(p);
}

return Collections.unmodifiableList(copy);
}

private static List<Object> copyParams(Object... params) {
if (params.length == 0) {
return ImmutableList.of();
}

final List<Object> copy = new ArrayList<>(params.length);
Collections.addAll(copy, params);
return Collections.unmodifiableList(copy);
}

private static Map<String, Object> copyParams(Map<String, Object> params) {
requireNonNull(params, "params");
if (params.isEmpty()) {
return Collections.emptyMap();
}

return Collections.unmodifiableMap(new HashMap<>(params));
}

@Override
@JsonProperty
public @Nullable Object id() {
return id;
}

@Override
@JsonProperty
public String method() {
return method;
}

@Override
@JsonProperty
public JsonRpcParameter params() {
return params;
}

@Override
@JsonProperty("jsonrpc")
public JsonRpcVersion version() {
return version;
}

@Override
public int hashCode() {
return Objects.hash(id, method, params, version);
}

@Override
public boolean equals(@Nullable Object obj) {
if (this == obj) {
return true;
}

if (!(obj instanceof JsonRpcRequest)) {
return false;
}

final JsonRpcRequest that = (JsonRpcRequest) obj;
return Objects.equals(id, that.id()) &&
Objects.equals(method, that.method()) &&
Objects.equals(params, that.params()) &&
Objects.equals(version, that.version());
}

@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("id", id())
.add("method", method())
.add("params", params())
.add("jsonrpc", version()).toString();
}
}
Loading
Loading