Skip to content

Commit

Permalink
remove T extends ResponseCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
venusdrogon committed Jun 7, 2024
1 parent 0f31e9e commit 185b8f0
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* Copyright (C) 2008 feilong
*
* Licensed 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
*
* http://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.feilong.context.converter;

import java.util.List;

import com.feilong.json.JsonToJavaConfig;
import com.feilong.json.JsonUtil;

/**
* json 字符串结果转换成list.
*
* @author <a href="https://github.com/ifeilong/feilong">feilong</a>
* @param <T>
* the generic type
* @since 4.1.0
*/
public class JsonStringToListConverter<T> extends AbstractStringToBeanConverter<List<T>>{

/** The json to java config. */
private JsonToJavaConfig jsonToJavaConfig;

//---------------------------------------------------------------

/**
* Instantiates a new json string to bean converter.
*/
public JsonStringToListConverter(){
super();
}

/**
* Instantiates a new json string to bean converter.
*
* @param rootClass
* the root class
*/
public JsonStringToListConverter(Class<T> rootClass){
super();
this.jsonToJavaConfig = new JsonToJavaConfig(rootClass);
}

/**
* Instantiates a new json string to bean converter.
*
* @param jsonToJavaConfig
* the json to java config
*/
public JsonStringToListConverter(JsonToJavaConfig jsonToJavaConfig){
super();
this.jsonToJavaConfig = jsonToJavaConfig;
}

//---------------------------------------------------------------
/*
* (non-Javadoc)
*
* @see com.feilong.bind.AbstractBeanClassStringToBeanConverter#handler(java.lang.Class, java.lang.String)
*/
@Override
protected List<T> handler(String inputJsonString){
return JsonUtil.toList(inputJsonString, jsonToJavaConfig);
}

//---------------------------------------------------------------

@Override
protected String formatValue(String value){
return JsonUtil.toString(value);
}

//---------------------------------------------------------------

/**
* Sets the json to java config.
*
* @param jsonToJavaConfig
* the jsonToJavaConfig to set
*/
public void setJsonToJavaConfig(JsonToJavaConfig jsonToJavaConfig){
this.jsonToJavaConfig = jsonToJavaConfig;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
* @param <T>
* 响应的字符串转换成的对象
* @since 1.11.3
* @since 4.1.0 remove T extends ResponseCommand
*/
public interface ResponseCommandBuilder<R extends InvokerRequest, T extends ResponseCommand> {
public interface ResponseCommandBuilder<R extends InvokerRequest, T> {

/**
* 通过发送请求,得到响应的对象.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@

import com.feilong.context.beanproperty.SimpleHttpTypeBeanProperty;
import com.feilong.context.converter.JsonStringToBeanConverter;
import com.feilong.context.converter.JsonStringToListConverter;
import com.feilong.context.converter.StringToBeanConverter;
import com.feilong.context.invoker.http.DefaultHttpRequestBuilder;
import com.feilong.context.invoker.http.HttpRequestBuilder;
import com.feilong.context.invoker.http.HttpResponseStringBuilder;
import com.feilong.context.invoker.http.RequestBodyBuilder;
import com.feilong.context.invoker.http.SimpleMapRequestHeaderBuilder;
import com.feilong.json.JsonHelper;
import com.feilong.lib.lang3.StringUtils;
import com.feilong.net.http.HttpMethodType;

/**
Expand All @@ -41,9 +44,9 @@
* @see HttpResponseStringBuilder
* @see DefaultHttpRequestBuilder
* @since 3.4.1
* @since 4.1.0 remove T extends ResponseCommand
*/
public class SimpleHttpAndJsonResponseCommandBuilder<R extends InvokerRequest, T extends ResponseCommand>
extends AbstractResponseCommandBuilder<R, T>{
public class SimpleHttpAndJsonResponseCommandBuilder<R extends InvokerRequest, T> extends AbstractResponseCommandBuilder<R, T>{

/** 提交地址. */
private String uri;
Expand Down Expand Up @@ -149,9 +152,13 @@ public SimpleHttpAndJsonResponseCommandBuilder(String uri, String method, Map<St
* 获得 字符串转换成bean 转换器.
*
* @return the 字符串转换成bean 转换器
* @since 4.1.0 add param responseString
*/
@Override
protected StringToBeanConverter<T> createStringToBeanConverter(){
protected StringToBeanConverter<T> createStringToBeanConverter(String responseString){
if (JsonHelper.isNeedConvertToJSONArray(StringUtils.trim(responseString))){
return new JsonStringToListConverter(responseCommandRootClass);
}
return new JsonStringToBeanConverter<>(responseCommandRootClass);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,7 @@ public void test(){
List<ItemDto> convert = converter.convert(json);

//---------------------------------------------------------------

if (LOGGER.isInfoEnabled()){
LOGGER.info(JsonUtil.format(convert));
}

//---------------------------------------------------------------

LOGGER.info(JsonUtil.format(convert));
// assertThat(convert, allOf(hasProperty("city", is("上海"))));
}
}

0 comments on commit 185b8f0

Please sign in to comment.