Skip to content

Commit

Permalink
Update JSON and template encoders.
Browse files Browse the repository at this point in the history
  • Loading branch information
gk-brown committed Oct 13, 2024
1 parent d9adf73 commit 8546ec4
Show file tree
Hide file tree
Showing 12 changed files with 15 additions and 163 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ public String getContentType() {
public void encodeRequest(Object body, OutputStream outputStream) throws IOException {
var jsonEncoder = new JSONEncoder();

jsonEncoder.write(BeanAdapter.adapt(body), outputStream);
jsonEncoder.write(body, outputStream);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

package org.httprpc.kilo.io;

import org.httprpc.kilo.beans.BeanAdapter;

import java.io.IOException;
import java.io.Writer;
import java.util.Date;
Expand Down Expand Up @@ -54,7 +56,7 @@ public void write(Object value, Writer writer) throws IOException {
writer = new BufferedWriter(writer);

try {
encode(value, writer);
encode(BeanAdapter.adapt(value), writer);
} finally {
writer.flush();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

package org.httprpc.kilo.io;

import org.httprpc.kilo.beans.BeanAdapter;

import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
Expand Down Expand Up @@ -469,7 +471,7 @@ public void write(Object value, Writer writer) throws IOException {
writer = new BufferedWriter(writer);

try {
encode(value, writer, reader);
encode(BeanAdapter.adapt(value), writer, reader);
} finally {
writer.flush();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public Object apply(Object value) {
var writer = new StringWriter();

try {
jsonEncoder.write(BeanAdapter.adapt(value), writer);
jsonEncoder.write(value, writer);
} catch (IOException exception) {
throw new RuntimeException(exception);
}
Expand Down
3 changes: 1 addition & 2 deletions kilo-server/src/main/java/org/httprpc/kilo/IndexServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.httprpc.kilo.beans.BeanAdapter;
import org.httprpc.kilo.io.JSONEncoder;
import org.httprpc.kilo.io.TemplateEncoder;

Expand All @@ -38,7 +37,7 @@ public class IndexServlet extends HttpServlet {
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
var serviceDescriptors = BeanAdapter.adapt(WebService.getServiceDescriptors());
var serviceDescriptors = WebService.getServiceDescriptors();

var accept = request.getHeader("Accept");

Expand Down
6 changes: 3 additions & 3 deletions kilo-server/src/main/java/org/httprpc/kilo/WebService.java
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ protected void service(HttpServletRequest request, HttpServletResponse response)

var jsonEncoder = new JSONEncoder();

jsonEncoder.write(new BeanAdapter(serviceDescriptor), response.getOutputStream());
jsonEncoder.write(serviceDescriptor, response.getOutputStream());
} else {
response.setContentType(String.format("%s;charset=%s", TEXT_HTML, UTF_8));

Expand All @@ -806,7 +806,7 @@ protected void service(HttpServletRequest request, HttpServletResponse response)

templateEncoder.write(mapOf(
entry("contextPath", request.getContextPath()),
entry("service", new BeanAdapter(serviceDescriptor))
entry("service", serviceDescriptor)
), response.getOutputStream());
}

Expand Down Expand Up @@ -1166,7 +1166,7 @@ protected void encodeResult(HttpServletRequest request, HttpServletResponse resp

var jsonEncoder = new JSONEncoder();

jsonEncoder.write(BeanAdapter.adapt(result), response.getOutputStream());
jsonEncoder.write(result, response.getOutputStream());
}

/**
Expand Down
4 changes: 2 additions & 2 deletions kilo-test/src/test/java/org/httprpc/kilo/test/Examples.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public static void customPropertyKeys() throws IOException {

var jsonEncoder = new JSONEncoder();

jsonEncoder.write(new BeanAdapter(person), System.out);
jsonEncoder.write(person, System.out);

System.out.println();
}
Expand Down Expand Up @@ -274,7 +274,7 @@ private static void encodeTreeNode(Writer writer) throws IOException {

var jsonEncoder = new JSONEncoder();

jsonEncoder.write(new BeanAdapter(root), writer);
jsonEncoder.write(root, writer);
}

private static void decodeTreeNode(Reader reader) throws IOException {
Expand Down

This file was deleted.

3 changes: 1 addition & 2 deletions kilo-test/src/test/kotlin/org/httprpc/kilo/test/UserTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package org.httprpc.kilo.test

import org.httprpc.kilo.WebServiceProxy
import org.httprpc.kilo.beans.BeanAdapter
import org.httprpc.kilo.io.JSONEncoder
import java.net.URI

Expand Down Expand Up @@ -50,7 +49,7 @@ fun main() {

val jsonEncoder = JSONEncoder()

jsonEncoder.write(BeanAdapter.adapt(users), System.out)
jsonEncoder.write(users, System.out)

println()
}

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 8546ec4

Please sign in to comment.