Giter Site home page Giter Site logo

jsoncat's Introduction

jsoncat's People

Contributors

coderyang123 avatar hellohello-tom avatar iochenlei avatar liuxiany avatar snailclimb avatar zshnb avatar

Stargazers

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

Watchers

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

jsoncat's Issues

REST Assured 会自动将对象转换为 JSON 吗?

Guide 哥,有个序列化的疑问想问下。

问题

在测试代码 test/java/com/github/demo/user/UserControllerTest 中,最后一个测试方法 should_create_user_successful 中对 user 进行序列化。如果不进行序列化,也能测试通过。

分析

在一篇文章 Testing REST Endpoints Using REST Assured 看到如下:

REST Assured makes the conversion automatically to a JSON object.

测试

我尝试了如下更改,依然以通过测试:

    @Test
    void should_create_user_successful() {
        UserDto user = new UserDto("压缩", "哈撒尅", 18);
        with()//.body(jacksonSerializer.serialize(user))     // 我的修改
                .body(user)                                  // 我的修改
                .header("Content-Type", "application/json")
                .when().post("/user")
                .then().
                .statusCode(200);
    }

我的结论

这么说来,这里是不是不需要序列化,直接传对象进去即可自动转化呢?

.body() 的实现如下:

// groovy
RequestSpecification body(Object object) {
    notNull object, "object"
    if (!isSerializableCandidate(object)) {
      return body(object.toString());
    }

    this.requestBody = ObjectMapping.serialize(object, requestContentType, findEncoderCharsetOrReturnDefault(requestContentType), null, objectMappingConfig(), restAssuredConfig().getEncoderConfig());
    this
  }

* 第一次提问,感谢 Guide 哥辛苦开源!

gradle源

要不还是加上阿里云的gradle源吧,不然太慢了。
对于我这种小白来说,下载可能就要好久。。。

Gradle跑不起来

请问一下这是什么问题啊,肝不动了
Plugin [id: 'com.github.spotbugs', version: '4.3.0'] was not found in any of the following sources:

  • Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
  • Plugin Repositories (could not resolve plugin artifact 'com.github.spotbugs:com.github.spotbugs.gradle.plugin:4.3.0')
    Searched in the following repositories:
    Gradle Central Plugin Repository

循环依赖的处理不正确

代码截图
image

期望效果
应该首先保证对象的查找容器中已有的单例对象,而不是每次实例化不完整的对象,这样处理之后其实已经可以完成循环依赖问题处理了,但是如果只使用一级缓存来处理的话,会导致不完整的对象可以被框架使用者提前获取到,利用两级缓存来处理,一级缓存放入完整对象,二级缓存放入不完整对象,可以提前暴露完成注入

循环依赖在这是起什么作用?

jsoncat里面是一次性把Bean全部创建出来,然后再遍历每个bean,注入依赖。这样不会存在递归爆栈的问题,所以不是很懂为什么需要解决循环依赖,也不是很懂这个循环依赖的代码。

依赖注入错误

演示说明
A和B都依赖C,然后C依赖与D,其实没有循环依赖问题,演示结果说明依赖注入不正确!

演示结果
image

问题分析
·
image

添加默认编码

增加 .editorconfig 文件 添加默认编码,在启动时发现GBK乱码问题

# http://editorconfig.org
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.{adoc,yml}]
indent_size = 2

[script/*]
indent_style = tab

循环依赖 bug

  1. 没有逐层注入依赖,如图所示注入的依赖中的属性为 null
    image

解决循环依赖问题时传参是否有误

/** * 二级缓存解决循环依赖问题 */ private Object resolveCircularDependency(Object beanInstance, Object beanFieldInstance, String beanFieldName) { if (SINGLETON_OBJECTS.containsKey(beanFieldName)) { beanFieldInstance = SINGLETON_OBJECTS.get(beanFieldName); } else { SINGLETON_OBJECTS.put(beanFieldName, beanFieldInstance); initialize(beanInstance); } return beanFieldInstance; }
initialize()方法是否应当传入字段实例beanFieldInstance

自动装配问题

注入到容器的时候,用的类的名字或者,component的value值。自动装配的时候,只用类的名字去get而没用用component的value值。如果一个bean,用component注解注入容器,但是用的别名,别名和类名不一样,就get不出来了。

自建项目无法启动

Guide哥,我试着照着项目敲了一遍,启动时出现这个错误,网上查了一圈也没能解决,想请教一下你

Execution failed for task ':JsonCatApplication.main()'.
Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_212.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1

环境
macOs 10.15.6
IDEA Ultimate 2020.1.1
JDK 1.8

ps.我直接运行你的项目是没有这个问题的

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.